package cc.comac.mom.datahandlers.entity;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import com.alibaba.ans.shaded.com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cc.comac.mom.bean.QarRestrictedPart;
import cc.comac.mom.bean.QualityAsrCheckForm;
import cc.comac.mom.bean.QualityAsrFeaturesBean;
import cc.comac.mom.bean.QualityAttachmentGroup;
import cc.comac.mom.bean.QualityParam;
import cc.comac.mom.bean.QualityPclrTestInvoice;
import cc.comac.mom.bean.QualityPclrTestInvoiceDetailBean;
import cc.comac.mom.bean.QualityPlanToDo;
import cc.comac.mom.bean.QualityQarBasicStandardCheck;
import cc.comac.mom.bean.QualityQarBasicStandardRequirement;
import cc.comac.mom.bean.QualityQarCheckInvoice;
import cc.comac.mom.bean.QualityQarSelectBean;
import cc.comac.mom.bean.QualityQarSelectResultBean;
import cc.comac.mom.bean.QualityQarSelectReturnBean;
import cc.comac.mom.bean.QualityQarSplitBean;
import cc.comac.mom.bean.QualityQarTaskQuery;
import cc.comac.mom.bean.QualityQarVerifyPlanBean;
import cc.comac.mom.bean.QualityReject;
import cc.comac.mom.bean.QualitySapPurchaseOrder;
import cc.comac.mom.bean.QuqlityQarCheckItem;
import cc.comac.mom.dao.entity.QualityAsrCheckFormDao;
import cc.comac.mom.dao.entity.QualityFrrFormEntityDao;
import cc.comac.mom.dao.entity.QualityPclrTestInvoiceDao;
import cc.comac.mom.dao.entity.QualityPclrTestInvoiceDetailDao;
import cc.comac.mom.dao.entity.QualityQarBasicStandardDao;
import cc.comac.mom.dao.entity.QualityQarBasicStandardRequirementDao;
import cc.comac.mom.dao.entity.QualityQarCheckInvoiceDao;
import cc.comac.mom.dao.entity.QualityQarConditionalSentMaterielDao;
import cc.comac.mom.dao.entity.QualityQarTaskQueryDao;
import cc.comac.mom.dao.entity.QualityQarVerifyPlanDao;
import cc.comac.mom.datahandlers.entity.soapreceive.ConditionalSentMaterielReceive;
import cc.comac.mom.entity.QarRestrictedPartEntity;
import cc.comac.mom.entity.QualityAsrCheckFormEntity;
import cc.comac.mom.entity.QualityFrrFormEntity;
import cc.comac.mom.entity.QualityPclrTestInvoiceDetailEntity;
import cc.comac.mom.entity.QualityPclrTestInvoiceEntity;
import cc.comac.mom.entity.QualityPlanToDoEntity;
import cc.comac.mom.entity.QualityQarBasicStandardCheckEntity;
import cc.comac.mom.entity.QualityQarBasicStandardEntity;
import cc.comac.mom.entity.QualityQarBasicStandardRequirementEntity;
import cc.comac.mom.entity.QualityQarCheckInvoiceEntity;
import cc.comac.mom.entity.QualityQarConditionalSentMaterielEntity;
import cc.comac.mom.entity.QualityQarTaskQueryEntity;
import cc.comac.mom.entity.QualityQarVerifyPlanEntity;
import cc.comac.mom.entity.QualitySapPurchaseOrderEntity;
import cc.comac.mom.entity.QuqlityQarCheckItemEntity;
import cc.comac.mom.redis.IdFactory;
import cc.comac.mom.util.BaseEntityDataUtil;
import cc.comac.mom.util.DataStatus;
import cc.comac.mom.util.MomConstants;
import cc.comac.mom.util.ParamUtils;
import cc.comac.mom.util.ResultBean;
import cc.comac.mom.util.TimeUtil;

@Component
@Transactional
public class QualityQarCheckInvoiceDataHandler
		extends ServiceImpl<QualityQarCheckInvoiceDao, QualityQarCheckInvoiceEntity> {

	@Autowired
	private QarRestrictedPartDataHandler qarRestrictedPartDataHandler;
	@Autowired
	private QualityQarVerifyPlanDao qualityQarVerifyPlanDao;

	@Autowired
	private BaseEntityDataUtil baseEntityDataUtil;

	@Autowired
	private QualityQarCheckInvoiceDao qualityQarCheckInvoiceDao;

	@Autowired
	private QualityPlanToDoDataHandler qualityPlanToDoDataHandler;
//	@Autowired
//	private QualityQarBasicStandardDataHanldler qualityQarBasicStandardDataHanldler;

	@Autowired
	private QualityPclrTestInvoiceDataHandler qualityPclrTestInvoiceDataHandler;
	@Autowired
	private QualityQarBasicStandardDao qualityQarBasicStandardDao;
	@Autowired
	private QualityParamDataHandler qualityParamDataHandler;

	@Autowired
	private QualityAsrCheckFormDataHandler qualityAsrCheckFormDataHandler;

	@Autowired
	private QualityQarTaskQueryDataHandler qualityQarTaskQueryDataHandler;

	@Autowired
	private QualityQarTaskQueryDao qualityQarTaskQueryDao;

	@Autowired
	private UniversalNumberGenerationDataHandler universalNumberGenerationDataHandler;

	@Autowired
	private QualityQarBasicStandardRequirementDao qualityQarBasicStandardRequirementDao;// 实验要求

	@Autowired
	private QualityQarBasicStandardAsrFeaturesDataHandler qualityQarBasicStandardAsrFeaturesDataHandler;// asr检验

	@Autowired
	private QualityQarBasicStandardCheckDataHandler qualityQarBasicStandardCheckDataHandler;// 检验特性

	@Autowired
	private QuqlityQarCheckItemDataHandler quqlityQarCheckItemDataHandler;

	@Autowired
	private QualityPclrTestInvoiceDao qualityPclrTestInvoiceDao;

	@Autowired
	private QualityAsrCheckFormDao qualityAsrCheckFormDao;

	@Autowired
	private QualityRejectDataHandler qualityRejectDataHandler;

	@Resource
	private IdFactory idFactory;

	@Autowired
	private QualityAttachmentGroupDataHandler qualityAttachmentGroupDataHandler;

	@Autowired
	private ConditionalSentMaterielReceive conditionalSentMaterielReceive;

	@Autowired
	private QualityQarConditionalSentMaterielDao qualityQarConditionalSentMaterielDao;

	@Autowired
	private QualityFrrFormEntityDao qualityFrrFormEntityDao;

	@Autowired
	private QualitySapPurchaseOrderDataHandler qualitySapPurchaseOrderDataHandler;

	@Autowired
	private QualityPclrTestInvoiceDetailDao QualityPclrTestInvoiceDetailDao;

	@Autowired
	private QualityPclrTestInvoiceDetailDao qualityPclrTestInvoiceDetailDao;
	@Autowired
	private qualityPclrTestInvoiceDetailDataHandler qualityPclrTestInvoiceDetailDataHandler;

	@Autowired
	private QualityQarCheckInvoiceDataHandler qualityQarCheckInvoiceDataHandler;

	public ResultBean insert(QualityQarCheckInvoice obj) {
		ResultBean resultBean = new ResultBean(true);
		if (obj == null || obj.getInnerData() == null) {
			resultBean.setErrorMessge("数据为空");
			return resultBean;
		}
		QualityQarCheckInvoiceEntity innerData = obj.getInnerData();
		baseEntityDataUtil.setBaseEntityData(innerData);
		int insert = qualityQarCheckInvoiceDao.insert(innerData);
		if (insert < 1) {
			resultBean.setErrorMessge("保存QAR信息失败");
			return resultBean;
		}
		return resultBean;

	}

	public ResultBean insertBatch(List<QualityQarCheckInvoice> list) {
		ResultBean resultBean = new ResultBean(true);
		if (list == null || list.size() < 1) {
			resultBean.setErrorMessge("数据为空");
			return resultBean;
		}
		ArrayList<QualityQarCheckInvoiceEntity> listEntity = new ArrayList<QualityQarCheckInvoiceEntity>();
		for (QualityQarCheckInvoice item : list) {
			QualityQarCheckInvoiceEntity innerData = item.getInnerData();
			if (innerData != null) {
				baseEntityDataUtil.setBaseEntityData(innerData);
				listEntity.add(innerData);
			}
		}

		boolean saveBatch = this.saveBatch(listEntity);
		if (!saveBatch) {
			resultBean.setErrorMessge("批量保存QAR信息失败");
			return resultBean;
		}
		return resultBean;

	}

	// 验证母本信息是否存在,不存在将生成计划待办信息
	public void checkMaterialExists(List<QualitySapPurchaseOrder> list) {
		if (list != null && list.size() > 0) {
			ArrayList<QualityPlanToDo> listQualityPlanToDo = new ArrayList<QualityPlanToDo>();
			for (QualitySapPurchaseOrder item : list) {

				QualitySapPurchaseOrderEntity innerData = item.getInnerData();
				if (innerData != null) {
					QueryWrapper<QualityQarBasicStandardEntity> queryWrapper = new QueryWrapper<QualityQarBasicStandardEntity>();
					queryWrapper.eq("row_status", 1);
					queryWrapper.eq("part_number", innerData.getPaiHao());
					queryWrapper.like("material_number", innerData.getMaterial());
					QualityQarBasicStandardEntity qualityQarBasicStandardEntity = qualityQarBasicStandardDao
							.selectOne(queryWrapper);
					if (qualityQarBasicStandardEntity == null) {
						// 母本不存在
						QualityPlanToDo qualityPlanToDo = new QualityPlanToDo();
						QualityPlanToDoEntity qualityPlanToDoEntity = new QualityPlanToDoEntity();
						qualityPlanToDoEntity.setPartName(innerData.getMaterialDescription());
						qualityPlanToDoEntity.setPartNo(innerData.getPaiHao());
						qualityPlanToDoEntity.setMaterialNumber(innerData.getMaterial());
						qualityPlanToDoEntity.setToDoContent("母本信息不存在");
						qualityPlanToDoEntity.setToDoType(MomConstants.QUALITY_PLAN_TO_DO_TYPE_EXCEPTION);// 母本异常类型
						qualityPlanToDoEntity.setStatus(MomConstants.QUALITY_PLAN_TO_DO_STATUS_UNTREATED);// 未处理状态
						qualityPlanToDo.setInnerData(qualityPlanToDoEntity);
						listQualityPlanToDo.add(qualityPlanToDo);
					}
				}
			}
			if (listQualityPlanToDo != null && listQualityPlanToDo.size() > 0) {
				qualityPlanToDoDataHandler.insertBatch(listQualityPlanToDo);
			}
		}

	}

	
	/**
	 * 1.1 当来料存在物料凭证时为采购单数据时，判断是否存在对应母本，不存在生成异常提醒，存在时，保存数据到采购单
	 * 1.判断母本是否存在，不存在生成母本异常提醒 ,存在如果是升版，生成母本升版提醒，结束
	 **/
	public void createQar(List<QualitySapPurchaseOrder> list) {
		// 计划待办集合
		ArrayList<QualityPlanToDo> listQualityPlanToDo = new ArrayList<QualityPlanToDo>();
		// qar查询集合
		ArrayList<QualityQarTaskQuery> listQualityQarTaskQuery = new ArrayList<QualityQarTaskQuery>();

		if (list != null && list.size() > 0) {
			for (QualitySapPurchaseOrder item : list) {
				baseEntityDataUtil.setBaseEntityData(item.getInnerData());
				QualitySapPurchaseOrderEntity innerData = item.getInnerData();
				// 当数据不为空，并且物料凭证为空时为入库单才生成代办任务
				if (innerData != null ) {
					// 1.查询母本数据并且判断母本是否存在，不存在生成母本异常提醒 结束
					QueryWrapper<QualityQarBasicStandardEntity> queryWrapper = new QueryWrapper<QualityQarBasicStandardEntity>();
					queryWrapper.eq("row_status", 1);
					queryWrapper.eq("part_number", innerData.getPaiHao());
					queryWrapper.eq("material_number", innerData.getMaterial());
					QualityQarBasicStandardEntity qualityQarBasicStandardEntity = qualityQarBasicStandardDao
							.selectOne(queryWrapper);
					// 判断是否已经生成过当前母本的异常提醒
					QueryWrapper<QualityPlanToDoEntity> queryWrapper2 = new QueryWrapper<QualityPlanToDoEntity>();
					queryWrapper2.eq("row_status", 1);
					queryWrapper2.eq("part_no", innerData.getPaiHao());
					queryWrapper2.eq("material_number", innerData.getMaterial());
					queryWrapper2.eq("status", MomConstants.QUALITY_PLAN_TO_DO_STATUS_UNTREATED);
					QualityPlanToDoEntity selectOneByQuery = qualityPlanToDoDataHandler.selectOneByQuery(queryWrapper2);
					if (qualityQarBasicStandardEntity == null && selectOneByQuery != null) {
						// 母本不存在
						QualityPlanToDo qualityPlanToDo = new QualityPlanToDo();
						QualityPlanToDoEntity qualityPlanToDoEntity = new QualityPlanToDoEntity();
						qualityPlanToDoEntity.setPartName(innerData.getMaterialDescription());
						qualityPlanToDoEntity.setPartNo(innerData.getPaiHao());
						qualityPlanToDoEntity.setMaterialNumber(innerData.getMaterial());
						qualityPlanToDoEntity.setToDoContent("母本信息不存在");
						qualityPlanToDoEntity.setReceiptNo(item.getInnerData().getPurchaseOrder());
						qualityPlanToDoEntity.setToDoType(MomConstants.QUALITY_PLAN_TO_DO_TYPE_EXCEPTION);// 母本异常类型
						qualityPlanToDoEntity.setStatus(MomConstants.QUALITY_PLAN_TO_DO_STATUS_UNTREATED);// 未处理状态
						qualityPlanToDo.setInnerData(qualityPlanToDoEntity);
						listQualityPlanToDo.add(qualityPlanToDo);
					}else {
						// 当母本存在，但是在升版中时，生成母本升版异常提醒
//						if (qualityQarBasicStandardEntity.getStatus()
//								.equals(MomConstants.QUALITY_QAR_BASIC_STANDARD_SHENGBAN) && selectOneByQuery != null) {
//							QualityPlanToDo qualityPlanToDo = new QualityPlanToDo();
//							QualityPlanToDoEntity qualityPlanToDoEntity = new QualityPlanToDoEntity();
//							qualityPlanToDoEntity.setPartName(innerData.getMaterialDescription());
//							qualityPlanToDoEntity.setPartNo(innerData.getPaiHao());
//							qualityPlanToDoEntity.setMaterialNumber(innerData.getMaterial());
//							qualityPlanToDoEntity.setToDoContent("母本在升版中");
//							qualityPlanToDoEntity.setReceiptNo(item.getInnerData().getPurchaseOrder());
//							qualityPlanToDoEntity.setToDoType(MomConstants.QUALITY_PLAN_TO_DO_TYPE_UPGRADE);// 母本异常类型
//							qualityPlanToDoEntity.setStatus(MomConstants.QUALITY_PLAN_TO_DO_STATUS_UNTREATED);// 未处理状态
//							qualityPlanToDo.setInnerData(qualityPlanToDoEntity);
//							listQualityPlanToDo.add(qualityPlanToDo);
//						}
					}
						
					// 保存QAR查询表记录 状态为 未发布
					if (StringUtils.isNotEmpty(item.getInnerData().getMaterialDocument())) {
						QualityQarTaskQuery qualityQarTaskQuery = this.createQualityQarTaskQuery(item,
								MomConstants.QUALITY_QAR_QUERY_NOISSUED, "");
						qualityQarTaskQuery.getInnerData().setRemark("母本未启用");
						long id = qualityQarBasicStandardEntity == null ? 0:qualityQarBasicStandardEntity.getId();
						qualityQarTaskQuery.getInnerData().setQarBasicStandardId(id ==  0 ? 0:id);
						qualityQarTaskQuery.getInnerData().setQualityPurchaseOrderInfoId(item.getInnerData().getId());
						qualityQarTaskQuery.getInnerData().setSerialNumber(item.getInnerData().getSerialNumber());
						qualityQarTaskQuery.getInnerData()
								.setProductType(item.getInnerData().getMaterialGroupDescription());
						qualityQarTaskQuery.getInnerData().setCaiLiaoXingShi(innerData.getCaiLiaoXingShi());
						qualityQarTaskQuery.getInnerData().setMaterial(innerData.getMaterial());
						qualityQarTaskQuery.getInnerData().setTaskExecutor(baseEntityDataUtil.getCurrentUser());
						qualityQarTaskQuery.getInnerData().setExecutorJobNumber(baseEntityDataUtil.getJobNumber());
						listQualityQarTaskQuery.add(qualityQarTaskQuery);
					}
				}

			}
			// 批量新增入库单数据
			if (list.size() > 0) {
				qualitySapPurchaseOrderDataHandler.insertBatch(list);
			}
			// 新增计划代办数据
			if (listQualityPlanToDo.size() > 0) {
				qualityPlanToDoDataHandler.insertBatch(listQualityPlanToDo);
			}
			// 新增任务查询数据
			if (listQualityQarTaskQuery.size() > 0) {
				for (QualityQarTaskQuery qualityQarTaskQuery : listQualityQarTaskQuery) {
					baseEntityDataUtil.setBaseEntityData(qualityQarTaskQuery.getInnerData());
				}
				qualityQarTaskQueryDataHandler.batchInsertQarTaskQuery(listQualityQarTaskQuery);
			}
		}
	}

	// 自动生成qar信息
	/**
	 * 1.1 当来料存在物料凭证时为采购单数据时，判断是否存在对应母本，不存在生成异常提醒，存在时，保存数据到采购单
	 * 1.判断母本是否存在，不存在生成母本异常提醒 结束 2.母本存在，判断是否为机载系统
	 * 判断纠正措施表中数据是否符合对应要求，判断让步frr数据是否满足对应数据 2.1 非机载系统 1.获取参数配置的关于 型号和材料 对应的一位
	 * 参数值，用来生成qar编号，如果获取不到，保存qar查询表记录，状态为 未发布 结束 2.用获取的参数值生成qar编号， 3.获取母本的实验要求
	 * 生成对应的PCLR、NDT 实验表单 4.获取母本的ASR检验，生成对应的ASR表单 5.保存QAR查询表记录，状态为 已发布
	 * 6.保存生成QAR检验单信息
	 * 
	 * 2.2 机载系统：保存qar查询表记录，状态为未发布
	 * 
	 * @param list
	 */
	public void autoCreateQar(List<QualitySapPurchaseOrder> list) {
		if (list != null && list.size() > 0) {
			// 计划待办集合
			ArrayList<QualityPlanToDo> listQualityPlanToDo = new ArrayList<QualityPlanToDo>();
			// qar集合
			ArrayList<QualityQarCheckInvoice> listQualityQarCheckInvoice = new ArrayList<QualityQarCheckInvoice>();
			// PCLR检验单、Ndt集合
			ArrayList<QualityPclrTestInvoice> listQualityPclrTestInvoice = new ArrayList<QualityPclrTestInvoice>();
			// qar查询集合
			ArrayList<QualityQarTaskQuery> listQualityQarTaskQuery = new ArrayList<QualityQarTaskQuery>();
			// ASR集合
			ArrayList<QualityAsrCheckForm> listQualityAsrCheckForm = new ArrayList<QualityAsrCheckForm>();
			// qar检验特性集合
			List<QuqlityQarCheckItem> listQuqlityQarCheckItem = null;

			for (QualitySapPurchaseOrder item : list) {

				QualitySapPurchaseOrderEntity innerData = item.getInnerData();
				if (innerData != null) {
					// 1.查询母本数据并且判断母本是否存在，不存在生成母本异常提醒 结束
					QueryWrapper<QualityQarBasicStandardEntity> queryWrapper = new QueryWrapper<QualityQarBasicStandardEntity>();
					queryWrapper.eq("row_status", 1);
					queryWrapper.eq("part_number", innerData.getPaiHao());
					queryWrapper.like("material_number", innerData.getMaterial());
					QualityQarBasicStandardEntity qualityQarBasicStandardEntity = qualityQarBasicStandardDao
							.selectOne(queryWrapper);
					if (qualityQarBasicStandardEntity == null) {
						// 母本不存在
						QualityPlanToDo qualityPlanToDo = new QualityPlanToDo();
						QualityPlanToDoEntity qualityPlanToDoEntity = new QualityPlanToDoEntity();
						qualityPlanToDoEntity.setPartName(innerData.getMaterialDescription());
						qualityPlanToDoEntity.setPartNo(innerData.getPaiHao());
						qualityPlanToDoEntity.setMaterialNumber(innerData.getMaterial());
						qualityPlanToDoEntity.setToDoContent("母本信息不存在");
						qualityPlanToDoEntity.setReceiptNo(item.getInnerData().getPurchaseOrder());
						qualityPlanToDoEntity.setToDoType(MomConstants.QUALITY_PLAN_TO_DO_TYPE_EXCEPTION);// 母本异常类型
						qualityPlanToDoEntity.setStatus(MomConstants.QUALITY_PLAN_TO_DO_STATUS_UNTREATED);// 未处理状态
						qualityPlanToDo.setInnerData(qualityPlanToDoEntity);
						listQualityPlanToDo.add(qualityPlanToDo);
						if (StringUtils.isNotEmpty(item.getInnerData().getMaterialDocument())) {
							continue;
						}
					} else {
						// 当是采购单时不会往下执行
						if (StringUtils.isNotEmpty(item.getInnerData().getMaterialDocument())) {
							continue;
						}
						// 校验母本状态是否为启用，是则生成查询记录，不生成qar检验单
						if (!qualityQarBasicStandardEntity.getStatus().equals("2")) {
							// 保存QAR查询表记录 状态为 未发布
							QualityQarTaskQuery qualityQarTaskQuery = this.createQualityQarTaskQuery(item,
									MomConstants.QUALITY_QAR_QUERY_NOISSUED, "");
							qualityQarTaskQuery.getInnerData().setRemark("母本未启用");
							qualityQarTaskQuery.getInnerData()
									.setQarBasicStandardId(qualityQarBasicStandardEntity.getId());
							listQualityQarTaskQuery.add(qualityQarTaskQuery);
							continue;
						}

						// 判断FRR让步信息 和纠正措施信息

						// 判断frr是否让步
						QueryWrapper<QualityFrrFormEntity> queryWrapper3 = new QueryWrapper<QualityFrrFormEntity>();
						queryWrapper3.eq("part_cde", item.getInnerData().getPaiHao());
						queryWrapper3.eq("material_num", item.getInnerData().getMaterial());
						queryWrapper3.eq("version", item.getInnerData().getBanCi());
						List<QualityFrrFormEntity> selectList2 = qualityFrrFormEntityDao.selectList(queryWrapper3);
						if (selectList2.size() > 0) {
							item.getInnerData().setIsFrr("1");
						} else {
							item.getInnerData().setIsFrr("0");
						}

						// 是否为纠正措施

						// 物料类型，
						String materialType = qualityQarBasicStandardEntity.getMaterialType();
						// 型号
						String model = qualityQarBasicStandardEntity.getModel();
						String year = String.valueOf(LocalDateTime.now().getYear());

						String modelValue = "";
						String materialTypeValue = "";
						String formType = "";

						String pclrNo = "";
						String ndtNo = "";
						String asrNo = "";
						QualityParam QualityParamModel = qualityParamDataHandler.getByParamTypeAndName("型号", model);
						modelValue = QualityParamModel.getInnerData().getParamValue();
						// 获取QAR流水号
						String qarSerialNumber = universalNumberGenerationDataHandler.getQarSerialNumber(year);
						// 生成QAR编号
						String qarNo = "QAR-" + modelValue + materialTypeValue + year.substring(year.length() - 2) + "-"
								+ qarSerialNumber;
						if (!materialType.contains("机载")) {
							// 不是机载系统，自动生成qar

							if (QualityParamModel == null || QualityParamModel.getInnerData().getParamValue() == null
									|| "".equals(QualityParamModel.getInnerData().getParamValue())) {
								// 获取不到型号参数值
								// 保存QAR查询表记录 状态为 未发布
								QualityQarTaskQuery qualityQarTaskQuery = this.createQualityQarTaskQuery(item,
										MomConstants.QUALITY_QAR_QUERY_NOISSUED, "");
								qualityQarTaskQuery.getInnerData().setRemark("获取不到型号参数值！用来生成QAR编号");
								qualityQarTaskQuery.getInnerData()
										.setQarBasicStandardId(qualityQarBasicStandardEntity.getId());
								listQualityQarTaskQuery.add(qualityQarTaskQuery);
								continue;// 跳出本次循环
							}
							QualityParam QualityParamMaterialType = qualityParamDataHandler.getByParamTypeAndName("材料",
									materialType);
							if (QualityParamMaterialType == null
									|| QualityParamMaterialType.getInnerData().getParamValue() == null
									|| "".equals(QualityParamMaterialType.getInnerData().getParamValue())) {
								// 获取不到材料参数值
								// 保存QAR查询表记录 状态为 未发布
								QualityQarTaskQuery qualityQarTaskQuery = this.createQualityQarTaskQuery(item,
										MomConstants.QUALITY_QAR_QUERY_NOISSUED, "");
								qualityQarTaskQuery.getInnerData().setRemark("获取不到材料参数值！用来生成QAR编号");
								qualityQarTaskQuery.getInnerData()
										.setQarBasicStandardId(qualityQarBasicStandardEntity.getId());
								qualityQarTaskQuery.getInnerData().setQarNo(qarNo);
								listQualityQarTaskQuery.add(qualityQarTaskQuery);
								continue;// 跳出本次循环
							}
							materialTypeValue = QualityParamMaterialType.getInnerData().getParamValue();
							formType = QualityParamMaterialType.getInnerData().getParamDetail();
							// 生成QAR编号
//							String qarNo = "QAR-" + modelValue + materialTypeValue + year.substring(year.length() - 2)
//									+ "-" + qarSerialNumber;
							// 验证实验要求
							QueryWrapper<QualityQarBasicStandardRequirementEntity> queryWrapper2 = new QueryWrapper<QualityQarBasicStandardRequirementEntity>();
							queryWrapper.eq("row_status", 1);
							queryWrapper.eq("requirement_type", MomConstants.QUALITY_QAR_REQUIREMENT_TYPE_TEST);
							queryWrapper.eq("qar_basic_standard_id", qualityQarBasicStandardEntity.getId());
							List<QualityQarBasicStandardRequirementEntity> selectList = qualityQarBasicStandardRequirementDao
									.selectList(queryWrapper2);
							if (selectList != null && selectList.size() > 0) {
								for (QualityQarBasicStandardRequirementEntity item1 : selectList) {
									String testName = item1.getRequirementName();
									if (testName.equalsIgnoreCase("MAT")) {
										// 说明要生成pclr实验单
										pclrNo = qarNo + "-PCLR";
										// 预留生成PCLR检验单
										QualityPclrTestInvoice qualityPclrTestInvoice = new QualityPclrTestInvoice();
										QualityPclrTestInvoiceEntity qualityPclrTestInvoiceEntity = new QualityPclrTestInvoiceEntity();
										qualityPclrTestInvoiceEntity.setTestNo(pclrNo);
										qualityPclrTestInvoiceEntity.setQarNo(qarNo);
										qualityPclrTestInvoiceEntity.setTestType("PCLR");
										qualityPclrTestInvoiceEntity.setMaterialType(materialType);
										qualityPclrTestInvoiceEntity.setProductModel(model);
										qualityPclrTestInvoiceEntity.setFormType(formType);
										qualityPclrTestInvoiceEntity
												.setStatus(MomConstants.QUALITY_PCLR_STATUS_DISPATCH);// 调度中
										qualityPclrTestInvoiceEntity
												.setPrepareUser(qualityQarBasicStandardEntity.getCreator());
										qualityPclrTestInvoiceEntity
												.setDepartment(qualityQarBasicStandardEntity.getDepartment());
										qualityPclrTestInvoiceEntity.setTestFile(item1.getRequirementName() + "-"
												+ item1.getMatNumber() + "-" + item1.getTestItemQuatity());
										qualityPclrTestInvoiceEntity.setTestDate(TimeUtil.getLocalDate());
										qualityPclrTestInvoiceEntity.setMaterialDetail("零件名称:"
												+ qualityQarBasicStandardEntity.getPartName() + "; 零件号:"
												+ qualityQarBasicStandardEntity.getPartNumber() + "; 更改字母 :"
												+ qualityQarBasicStandardEntity.getChangedLetters() + "; 状态:"
												+ qualityQarBasicStandardEntity.getMaterialStatus() + "; 规范/标准:"
												+ qualityQarBasicStandardEntity.getStandard() + "; 规范/标准版次:"
												+ qualityQarBasicStandardEntity.getStandardVersion() + "; 工艺材料编号:"
												+ qualityQarBasicStandardEntity.getRouteMaterialNumber() + "; 型别:"
												+ qualityQarBasicStandardEntity.getType() + "; 类别/组合物别:级别:"
												+ qualityQarBasicStandardEntity.getCategory() + "; 形式/形态:"
												+ qualityQarBasicStandardEntity.getShape() + "; 规格:"
												+ qualityQarBasicStandardEntity.getNorms() + "; 色号:"
												+ qualityQarBasicStandardEntity.getColorCode() + "; 性能要求:"
												+ qualityQarBasicStandardEntity.getPerformanceRequirement()
												+ "; 热处理/炉/批号:" + item.getInnerData().getBatchNumber()// 入库单来
												+ "; 试样数量 :" + qualityQarBasicStandardEntity.getSamplesQuantity()
												+ "; 试样规格:" + qualityQarBasicStandardEntity.getSamplesSize());
										qualityPclrTestInvoice.setInnerData(qualityPclrTestInvoiceEntity);
										listQualityPclrTestInvoice.add(qualityPclrTestInvoice);
										break;
									}
								}
								String testFile = "";
								for (QualityQarBasicStandardRequirementEntity item1 : selectList) {
									String testName = item1.getRequirementName();
									if (!testName.equalsIgnoreCase("MAT")) {
										testFile = item1.getRequirementName() + ";";
									}
								}
								if (!testFile.equals("")) {
									// 说明要生成NDT实验单
									ndtNo = qarNo + "-NDT";
									// 预留生成NDT检验单
									QualityPclrTestInvoice qualityPclrTestInvoice = new QualityPclrTestInvoice();
									QualityPclrTestInvoiceEntity qualityPclrTestInvoiceEntity = new QualityPclrTestInvoiceEntity();
									qualityPclrTestInvoiceEntity.setTestNo(ndtNo);
									qualityPclrTestInvoiceEntity.setQarNo(qarNo);
									qualityPclrTestInvoiceEntity.setTestType("NDT");
									qualityPclrTestInvoiceEntity.setMaterialType(materialType);
									qualityPclrTestInvoiceEntity.setProductModel(model);
									qualityPclrTestInvoiceEntity.setFormType(formType);
									qualityPclrTestInvoiceEntity.setStatus(MomConstants.QUALITY_PCLR_STATUS_DISPATCH);// 调度中
									qualityPclrTestInvoiceEntity
											.setPrepareUser(qualityQarBasicStandardEntity.getCreator());
									qualityPclrTestInvoiceEntity
											.setDepartment(qualityQarBasicStandardEntity.getDepartment());
									qualityPclrTestInvoiceEntity.setTestFile(testFile);
									qualityPclrTestInvoiceEntity.setTestDate(TimeUtil.getLocalDate());
									qualityPclrTestInvoiceEntity.setMaterialDetail(
											"零件名称:" + qualityQarBasicStandardEntity.getPartName() + "; 零件号:"
													+ qualityQarBasicStandardEntity.getPartNumber() + "; 更改字母 :"
													+ qualityQarBasicStandardEntity.getChangedLetters() + "; 状态:"
													+ qualityQarBasicStandardEntity.getMaterialStatus() + "; 规范/标准:"
													+ qualityQarBasicStandardEntity.getStandard() + "; 规范/标准版次:"
													+ qualityQarBasicStandardEntity.getStandardVersion() + "; 工艺材料编号:"
													+ qualityQarBasicStandardEntity.getRouteMaterialNumber() + "; 型别:"
													+ qualityQarBasicStandardEntity.getType() + "; 类别/组合物别:级别:"
													+ qualityQarBasicStandardEntity.getCategory() + "; 形式/形态:"
													+ qualityQarBasicStandardEntity.getShape() + "; 规格:"
													+ qualityQarBasicStandardEntity.getNorms() + "; 色号:"
													+ qualityQarBasicStandardEntity.getColorCode() + "; 性能要求:"
													+ qualityQarBasicStandardEntity.getPerformanceRequirement()
													+ "; 热处理/炉/批号:" + item.getInnerData().getBatchNumber()// 入库单来
									);
									qualityPclrTestInvoice.setInnerData(qualityPclrTestInvoiceEntity);
									listQualityPclrTestInvoice.add(qualityPclrTestInvoice);

								}

							}
							// 验证ASR检验
							List<QualityAsrFeaturesBean> selectByQarBasicStandardId = qualityQarBasicStandardAsrFeaturesDataHandler
									.selectByQarBasicStandardId(qualityQarBasicStandardEntity.getId());
							if (selectByQarBasicStandardId != null && selectByQarBasicStandardId.size() > 0) {
								asrNo = qarNo + "-ASR";
								// 预留生成ASR检验单
								QualityAsrCheckForm qualityAsrCheckForm = new QualityAsrCheckForm();
								QualityAsrCheckFormEntity qualityAsrCheckFormEntity = new QualityAsrCheckFormEntity();
								qualityAsrCheckFormEntity.setAsrNumber(asrNo);
								qualityAsrCheckFormEntity.setQarNumber(qarNo);
								qualityAsrCheckFormEntity.setPartNumber(qualityQarBasicStandardEntity.getPartNumber());
								qualityAsrCheckFormEntity.setFormType(formType);
								qualityAsrCheckFormEntity.setProductModel(model);
								qualityAsrCheckFormEntity.setPartType(materialType);
								qualityAsrCheckFormEntity.setFoPoNumber(item.getInnerData().getPurchaseOrder());
								qualityAsrCheckFormEntity.setSupplierWorkshop(item.getInnerData().getVendorName());
								qualityAsrCheckFormEntity.setPlanRemark(qualityQarBasicStandardEntity.getPlanRemark());
								DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
								/*
								 * qualityAsrCheckFormEntity.setQualityPlan(qualityQarBasicStandardEntity.
								 * getCreator() + " " +
								 * df.format(qualityQarBasicStandardEntity.getCreationTime()));
								 */
								qualityAsrCheckFormEntity.setStatus(DataStatus.planning);
								qualityAsrCheckForm.setInnerData(qualityAsrCheckFormEntity);
								listQualityAsrCheckForm.add(qualityAsrCheckForm);

								//
							}

							// 获取检验特性
							listQuqlityQarCheckItem = this.createQarCheckItem(qualityQarBasicStandardEntity.getId(),
									qarNo);
							// 创建已发布QAR
							QualityQarTaskQuery qualityQarTaskQuery = this.createQualityQarTaskQuery(item,
									MomConstants.QUALITY_QAR_QUERY_ISSUED, qarNo);
							qualityQarTaskQuery.getInnerData().setQarNo(qarNo);
							listQualityQarTaskQuery.add(qualityQarTaskQuery);

							// 创建QAR检验单
							QualityQarCheckInvoice qualityQarCheckInvoice = new QualityQarCheckInvoice();
							QualityQarCheckInvoiceEntity qualityQarCheckInvoiceEntity = new QualityQarCheckInvoiceEntity();
							qualityQarCheckInvoiceEntity.setQarNo(qarNo);
							qualityQarCheckInvoiceEntity.setNdtNo(ndtNo);
							qualityQarCheckInvoiceEntity.setAsrNo(asrNo);
							qualityQarCheckInvoiceEntity.setFormType(formType);
							qualityQarCheckInvoiceEntity.setQarBasicStandardId(qualityQarBasicStandardEntity.getId());
							qualityQarCheckInvoiceEntity
									.setCurrentStatus(MomConstants.QUALITY_QAR_CURRENT_STATUS_STAYISSUED);
							qualityQarCheckInvoiceEntity.setPurchaseOrder(item.getInnerData().getPurchaseOrder());
							qualityQarCheckInvoiceEntity.setQuantity(item.getInnerData().getQuantity());
							qualityQarCheckInvoiceEntity.setUom(item.getInnerData().getBom());
							qualityQarCheckInvoiceEntity.setVendor(item.getInnerData().getVendorName());
							qualityQarCheckInvoiceEntity
									.setManufacturer(qualityQarBasicStandardEntity.getManufacturer());// 制造商
							// qualityQarCheckInvoiceEntity.setProductType(qualityQarBasicStandardEntity.getModel());
							qualityQarCheckInvoiceEntity.setPartType(item.getInnerData().getMaterialType());
							qualityQarCheckInvoiceEntity.setPartNo(item.getInnerData().getPaiHao());
							qualityQarCheckInvoiceEntity.setMaterialNumber(item.getInnerData().getMaterial());
							qualityQarCheckInvoiceEntity.setPartName(item.getInnerData().getMaterialDescription());
							qualityQarCheckInvoiceEntity
									.setChangedLetters(qualityQarBasicStandardEntity.getChangedLetters());
							qualityQarCheckInvoiceEntity.setStandard(qualityQarBasicStandardEntity.getStatus());
							qualityQarCheckInvoiceEntity
									.setRouteMaterialNumber(qualityQarBasicStandardEntity.getRouteMaterialNumber());
							qualityQarCheckInvoiceEntity.setType(qualityQarBasicStandardEntity.getType());
							qualityQarCheckInvoiceEntity.setCategory(qualityQarBasicStandardEntity.getCategory());
							qualityQarCheckInvoiceEntity.setLevel(qualityQarBasicStandardEntity.getLevel());
							qualityQarCheckInvoiceEntity.setShape(qualityQarBasicStandardEntity.getShape());
							qualityQarCheckInvoiceEntity.setNorms(qualityQarBasicStandardEntity.getNorms());
							qualityQarCheckInvoiceEntity
									.setMaterialType(qualityQarBasicStandardEntity.getMaterialType());
							qualityQarCheckInvoiceEntity
									.setMaterialScience(qualityQarBasicStandardEntity.getManufacturer());

							qualityQarCheckInvoiceEntity.setStoveNo(item.getInnerData().getVendorBatchNumber());// 炉批号就是供应商批次号
							qualityQarCheckInvoiceEntity.setModel(qualityQarBasicStandardEntity.getModel());
							qualityQarCheckInvoiceEntity.setAtpNo(qualityQarBasicStandardEntity.getAtpNumber());
							qualityQarCheckInvoiceEntity
									.setSoftwareNo(qualityQarBasicStandardEntity.getSoftwareNumber());
							qualityQarCheckInvoiceEntity
									.setSoftwareVersion(qualityQarBasicStandardEntity.getSoftwareRevision());
							qualityQarCheckInvoiceEntity
									.setRequiredSize(qualityQarBasicStandardEntity.getRequiredSize());
							qualityQarCheckInvoiceEntity
									.setSamplesQuantity(qualityQarBasicStandardEntity.getSamplesQuantity());
							qualityQarCheckInvoiceEntity.setPlanRemark(qualityQarBasicStandardEntity.getPlanRemark());
							qualityQarCheckInvoiceEntity
									.setPerformanceRequest(qualityQarBasicStandardEntity.getPerformanceRequirement());
							qualityQarCheckInvoiceEntity.setStandard(qualityQarBasicStandardEntity.getStandard());
							qualityQarCheckInvoiceEntity
									.setStandardVersion(qualityQarBasicStandardEntity.getStandardVersion());
							qualityQarCheckInvoiceEntity.setFigureNo(qualityQarBasicStandardEntity.getDrawingNumber());
							qualityQarCheckInvoiceEntity
									.setFigureVersion(qualityQarBasicStandardEntity.getDrawingRevision());
							qualityQarCheckInvoiceEntity.setMaterialDocument(item.getInnerData().getMaterialDocument());
							qualityQarCheckInvoiceEntity
									.setMaterialDocumentItem(item.getInnerData().getMaterialDocumentItem());
							qualityQarCheckInvoice.setInnerData(qualityQarCheckInvoiceEntity);
							listQualityQarCheckInvoice.add(qualityQarCheckInvoice);
						} else {// 机载系统，生成未发布qar
							QualityQarTaskQuery qualityQarTaskQuery = this.createQualityQarTaskQuery(item,
									MomConstants.QUALITY_QAR_QUERY_NOISSUED, "");
							qualityQarTaskQuery.getInnerData().setRemark("机载系统");
							qualityQarTaskQuery.getInnerData().setQarNo(qarNo);
							qualityQarTaskQuery.getInnerData().setId(idFactory.generateId());
							listQualityQarTaskQuery.add(qualityQarTaskQuery);
						}

					}
				}
			}
			// 保存母本异常提醒
			if (listQualityPlanToDo != null && listQualityPlanToDo.size() > 0) {
				// 批量插入计划代办
				qualityPlanToDoDataHandler.insertBatch(listQualityPlanToDo);
			}
			// 保存QAR查询记录
			if (listQualityQarTaskQuery != null && listQualityQarTaskQuery.size() > 0) {
				qualityQarTaskQueryDataHandler.batchInsertQarTaskQuery(listQualityQarTaskQuery);
			}
			// 保存PCLR和NDT检验单
			if (listQualityPclrTestInvoice != null && listQualityPclrTestInvoice.size() > 0) {
				qualityPclrTestInvoiceDataHandler.insertBatch(listQualityPclrTestInvoice);
			}

			// 保存qar检验
			if (listQuqlityQarCheckItem != null && listQuqlityQarCheckItem.size() > 0) {
				quqlityQarCheckItemDataHandler.insertBatch(listQuqlityQarCheckItem);
			}
			// 保存QAR检验单
			if (listQualityQarCheckInvoice != null) {
				// 批量插入Qar
				this.insertBatch(listQualityQarCheckInvoice);
			}
			// 保存ASR检验
			if (listQualityAsrCheckForm != null && listQualityAsrCheckForm.size() > 0) {
				qualityAsrCheckFormDataHandler.batchInsertAsrCheckForm(listQualityAsrCheckForm);
			}
		}

	}

	/**
	 * 手动创建qar
	 **/
	public ResultBean manualCreateQar(List<QualityQarCheckInvoice> list) {
		ResultBean resultBean = new ResultBean(true);
		if (list == null || list.size() < 1) {
			resultBean.setErrorMessge("数据为空");
			return resultBean;
		}
		// PCLR检验单、Ndt集合
		ArrayList<QualityPclrTestInvoice> listQualityPclrTestInvoice = new ArrayList<QualityPclrTestInvoice>();
		// ASR集合
		ArrayList<QualityAsrCheckForm> listQualityAsrCheckForm = new ArrayList<QualityAsrCheckForm>();
		// qar检验特性集合
		List<QuqlityQarCheckItem> listQuqlityQarCheckItem = null;
		// 实验限制要求
		List<QualityPclrTestInvoiceDetailEntity> basicStandardRequirementList = new ArrayList<QualityPclrTestInvoiceDetailEntity>();
		for (QualityQarCheckInvoice item : list) {
			QualityQarCheckInvoiceEntity innerData = item.getInnerData();
			if (innerData == null) {
				throw new RuntimeException("数据为空!");
			}
			QueryWrapper<QualityQarBasicStandardEntity> queryWrapper = new QueryWrapper<QualityQarBasicStandardEntity>();
			queryWrapper.eq("row_status", 1);
			queryWrapper.eq("part_number", innerData.getPartNo());// 件号
			queryWrapper.like("material_number", innerData.getMaterialNumber());// 物料号
			QualityQarBasicStandardEntity qualityQarBasicStandardEntity = qualityQarBasicStandardDao
					.selectOne(queryWrapper);
			if (qualityQarBasicStandardEntity == null) {
				// 母本不存在
				resultBean.setErrorMessge("母本不存在");
				return resultBean;
			} else {
				// 校验母本状态是否为启用
				if (!qualityQarBasicStandardEntity.getStatus().equals("2")) {
					resultBean
							.setErrorMessge("母本" + qualityQarBasicStandardEntity.getQarBasicStandardNumber() + ":未启用");
					return resultBean;
				}
				// 物料类型，
				String materialType = qualityQarBasicStandardEntity.getMaterialType();

				// 型号
				String model = qualityQarBasicStandardEntity.getModel();
				String year = String.valueOf(LocalDateTime.now().getYear());

				String modelValue = "";
				String materialTypeValue = "";
				String formType = "";

				String pclrNo = "";
				String ndtNo = "";
				String asrNo = "";
				Long ndtId = null;
				Long pclrId = null;

				// 获取QAR流水号
				String qarSerialNumber = universalNumberGenerationDataHandler.getQarSerialNumber(year);
				String nameByNo = ParamUtils.getMaterialByNo(model);
				QualityParam QualityParamModel = qualityParamDataHandler.getByParamTypeAndName("型号", nameByNo);
				if (QualityParamModel == null) {
					// 获取不到型号参数值
					resultBean.setErrorMessge("无法获取母本的型号配置的参数值  " + nameByNo);
					return resultBean;
				}
				modelValue = QualityParamModel.getInnerData().getParamValue();
				String nameByNo2 = ParamUtils.getNameByNo(materialType);
				QualityParam QualityParamMaterialValue = qualityParamDataHandler.getByParamTypeAndName("材料",
						nameByNo2);
				if (QualityParamMaterialValue == null
						|| QualityParamMaterialValue.getInnerData().getParamValue() == null
						|| "".equals(QualityParamMaterialValue.getInnerData().getParamValue())) {
					// 获取不到材料配置参数值
					resultBean.setErrorMessge("无法 获取材料配置参数值  " + nameByNo2);
					return resultBean;
				}
				materialTypeValue = QualityParamMaterialValue.getInnerData().getParamValue();
				formType = QualityParamMaterialValue.getInnerData().getParamDetail();
				// 生成QAR编号
				String qarNo = "QAR-" + modelValue + materialTypeValue + year.substring(year.length() - 2) + "-"
						+ qarSerialNumber;
				// 验证实验要求
				QueryWrapper<QualityQarBasicStandardRequirementEntity> queryWrapper2 = new QueryWrapper<QualityQarBasicStandardRequirementEntity>();
				queryWrapper2.eq("row_status", 1);
				queryWrapper2.eq("requirement_type", MomConstants.QUALITY_QAR_REQUIREMENT_TYPE_TEST);
				queryWrapper2.eq("qar_basic_standard_id", qualityQarBasicStandardEntity.getId());
				List<QualityQarBasicStandardRequirementEntity> selectList = qualityQarBasicStandardRequirementDao
						.selectList(queryWrapper2);
				if (selectList != null && selectList.size() > 0) {
					for (QualityQarBasicStandardRequirementEntity item1 : selectList) {
						String testName = item1.getRequirementName();
						pclrNo = qarNo + "-PCLR";
						pclrId = idFactory.generateId();
						if (testName.contains("MAT")) {
							// 说明要生成pclr实验单

							// 预留生成PCLR检验单
							QualityPclrTestInvoice qualityPclrTestInvoice = new QualityPclrTestInvoice();
							QualityPclrTestInvoiceEntity qualityPclrTestInvoiceEntity = new QualityPclrTestInvoiceEntity();
							qualityPclrTestInvoiceEntity.setTestNo(pclrNo);
							qualityPclrTestInvoiceEntity.setQarNo(qarNo);
							item.getInnerData().setQarNo(qarNo);
							qualityPclrTestInvoiceEntity.setTestType("PCLR");
							qualityPclrTestInvoiceEntity.setMaterialType(materialType);
							qualityPclrTestInvoiceEntity.setProductModel(model);
							qualityPclrTestInvoiceEntity.setFormType(formType);
							qualityPclrTestInvoiceEntity.setStatus(MomConstants.QUALITY_PCLR_STATUS_DISPATCH);// 调度中
							qualityPclrTestInvoiceEntity.setPrepareUser(qualityQarBasicStandardEntity.getCreator());
							qualityPclrTestInvoiceEntity.setDepartment(qualityQarBasicStandardEntity.getDepartment());
							qualityPclrTestInvoiceEntity.setId(pclrId);
							qualityPclrTestInvoiceEntity.setTestFile(item1.getRequirementName() + "-"
									+ item1.getMatNumber() + "-" + item1.getTestItemQuatity());
							qualityPclrTestInvoiceEntity.setTestDate(TimeUtil.getLocalDate());
							qualityPclrTestInvoiceEntity
									.setMaterialDetail("零件名称:" + qualityQarBasicStandardEntity.getPartName() + "; 零件号:"
											+ qualityQarBasicStandardEntity.getPartNumber() + "; 更改字母 :"
											+ qualityQarBasicStandardEntity.getChangedLetters() + "; 状态:"
											+ qualityQarBasicStandardEntity.getMaterialStatus() + "; 规范/标准:"
											+ qualityQarBasicStandardEntity.getStandard() + "; 规范/标准版次:"
											+ qualityQarBasicStandardEntity.getStandardVersion() + "; 工艺材料编号:"
											+ qualityQarBasicStandardEntity.getRouteMaterialNumber() + "; 型别:"
											+ qualityQarBasicStandardEntity.getType() + "; 类别/组合物别:级别:"
											+ qualityQarBasicStandardEntity.getCategory() + "; 形式/形态:"
											+ qualityQarBasicStandardEntity.getShape() + "; 规格:"
											+ qualityQarBasicStandardEntity.getNorms() + "; 色号:"
											+ qualityQarBasicStandardEntity.getColorCode() + "; 性能要求:"
											+ qualityQarBasicStandardEntity.getPerformanceRequirement() + "; 热处理/炉/批号:"
											+ item.getInnerData().getStoveNo() + "; 试样数量 :"
											+ qualityQarBasicStandardEntity.getSamplesQuantity() + "; 试样规格:"
											+ qualityQarBasicStandardEntity.getSamplesSize());
							qualityPclrTestInvoice.setInnerData(qualityPclrTestInvoiceEntity);
							listQualityPclrTestInvoice.add(qualityPclrTestInvoice);
							break;
						}
					}
					String testFile = "";
					for (QualityQarBasicStandardRequirementEntity item1 : selectList) {
						String testName = item1.getRequirementName();
						if (!testName.contains("MAT")) {
							testFile = item1.getRequirementName() + ";";
						}
					}
					ndtNo = qarNo + "-NDT";
					ndtId = idFactory.generateId();
					List<QualityPclrTestInvoice> collect = listQualityPclrTestInvoice.stream()
							.filter(item1 -> item1.getInnerData().getTestType().equals("NDT"))
							.collect(Collectors.toList());
					if (!testFile.equals("") && collect.size() == 0) {
						// 说明要生成NDT实验单
						// 预留生成NDT检验单
						QualityPclrTestInvoice qualityPclrTestInvoice = new QualityPclrTestInvoice();
						QualityPclrTestInvoiceEntity qualityPclrTestInvoiceEntity = new QualityPclrTestInvoiceEntity();
						qualityPclrTestInvoiceEntity.setTestNo(ndtNo);
						qualityPclrTestInvoiceEntity.setQarNo(qarNo);
						qualityPclrTestInvoiceEntity.setTestType("NDT");
						qualityPclrTestInvoiceEntity.setMaterialType(materialType);
						qualityPclrTestInvoiceEntity.setProductModel(model);
						qualityPclrTestInvoiceEntity.setFormType(formType);
						qualityPclrTestInvoiceEntity.setStatus(MomConstants.QUALITY_PCLR_STATUS_DISPATCH);// 调度中
						qualityPclrTestInvoiceEntity.setPrepareUser(qualityQarBasicStandardEntity.getCreator());
						qualityPclrTestInvoiceEntity.setDepartment(qualityQarBasicStandardEntity.getDepartment());
						qualityPclrTestInvoiceEntity.setTestFile(testFile);
						qualityPclrTestInvoiceEntity.setTestDate(TimeUtil.getLocalDate());
						qualityPclrTestInvoiceEntity.setId(ndtId);
						qualityPclrTestInvoiceEntity
								.setMaterialDetail("零件名称:" + qualityQarBasicStandardEntity.getPartName() + "; 零件号:"
										+ qualityQarBasicStandardEntity.getPartNumber() + "; 更改字母 :"
										+ qualityQarBasicStandardEntity.getChangedLetters() + "; 状态:"
										+ qualityQarBasicStandardEntity.getMaterialStatus() + "; 规范/标准:"
										+ qualityQarBasicStandardEntity.getStandard() + "; 规范/标准版次:"
										+ qualityQarBasicStandardEntity.getStandardVersion() + "; 工艺材料编号:"
										+ qualityQarBasicStandardEntity.getRouteMaterialNumber() + "; 型别:"
										+ qualityQarBasicStandardEntity.getType() + "; 类别/组合物别:级别:"
										+ qualityQarBasicStandardEntity.getCategory() + "; 形式/形态:"
										+ qualityQarBasicStandardEntity.getShape() + "; 规格:"
										+ qualityQarBasicStandardEntity.getNorms() + "; 色号:"
										+ qualityQarBasicStandardEntity.getColorCode() + "; 性能要求:"
										+ qualityQarBasicStandardEntity.getPerformanceRequirement() + "; 热处理/炉/批号:"
										+ item.getInnerData().getStoveNo());
						qualityPclrTestInvoice.setInnerData(qualityPclrTestInvoiceEntity);
						listQualityPclrTestInvoice.add(qualityPclrTestInvoice);

					}
				}

				// 查询母本对应的限制要求和实验要求数据，并存储一份到实验表单详情表quality_pclr_test_invoice_detail中
				QueryWrapper<QualityQarBasicStandardRequirementEntity> queryWrapper3 = new QueryWrapper<QualityQarBasicStandardRequirementEntity>();
				queryWrapper3.eq("row_status", 1);
				queryWrapper3.in("requirement_type", Arrays.asList(MomConstants.QUALITY_QAR_REQUIREMENT_TYPE_TEST, MomConstants.QUALITY_QAR_REQUIREMENT_TYPE_LIMIT));
				queryWrapper3.eq("qar_basic_standard_id", qualityQarBasicStandardEntity.getId());
				List<QualityQarBasicStandardRequirementEntity> selectList1 = qualityQarBasicStandardRequirementDao
						.selectList(queryWrapper2);

				// 将母本中的实验要求复制一份放到qar检验单中，防止母本升版会改动
				for (QualityQarBasicStandardRequirementEntity qualityQarBasicStandardRequirementEntity : selectList1) {
					qualityQarBasicStandardRequirementEntity.setQarBasicStandardId(item.getInnerData().getId());
				}
				// 将实验和限制要求数据存实验表单详情集合方便后面批量新增
				for (QualityQarBasicStandardRequirementEntity qualityQarBasicStandardRequirementEntity : selectList1) {
					QualityPclrTestInvoiceDetailEntity qualityPclrTestInvoiceDetailEntity = new QualityPclrTestInvoiceDetailEntity();
					qualityPclrTestInvoiceDetailEntity
							.setAircraftLimit(qualityQarBasicStandardRequirementEntity.getAircraftLimit());
					qualityPclrTestInvoiceDetailEntity
							.setMatNumber(qualityQarBasicStandardRequirementEntity.getMatNumber());
					qualityPclrTestInvoiceDetailEntity.setOther(qualityQarBasicStandardRequirementEntity.getOther());
					qualityPclrTestInvoiceDetailEntity.setQarBasicStandardId(item.getInnerData().getId());
					qualityPclrTestInvoiceDetailEntity.setRemark(qualityQarBasicStandardRequirementEntity.getRemark());
					qualityPclrTestInvoiceDetailEntity
							.setRequirementName(qualityQarBasicStandardRequirementEntity.getRequirementName());
					qualityPclrTestInvoiceDetailEntity
							.setRequirementType(qualityQarBasicStandardRequirementEntity.getRequirementType());
					qualityPclrTestInvoiceDetailEntity.setRowStatus(1);
					// 当为实验要求数据，赋值试验单据号
					if (qualityQarBasicStandardRequirementEntity.getRequirementType().equals(MomConstants.QUALITY_QAR_REQUIREMENT_TYPE_TEST)) {
						if (qualityQarBasicStandardRequirementEntity.getRequirementName().equalsIgnoreCase("MAT")) {

							qualityPclrTestInvoiceDetailEntity.setTestInvoiceId(pclrId);
						} else {
							qualityPclrTestInvoiceDetailEntity.setTestInvoiceId(ndtId);
						}
					}
					qualityPclrTestInvoiceDetailEntity
							.setTestItemQuatity(qualityQarBasicStandardRequirementEntity.getTestItemQuatity());
					baseEntityDataUtil.setBaseEntityData(qualityPclrTestInvoiceDetailEntity);
					basicStandardRequirementList.add(qualityPclrTestInvoiceDetailEntity);
				}
				// 验证ASR检验
				List<QualityAsrFeaturesBean> selectByQarBasicStandardId = qualityQarBasicStandardAsrFeaturesDataHandler
						.selectByQarBasicStandardId(qualityQarBasicStandardEntity.getId());
				if (selectByQarBasicStandardId != null && selectByQarBasicStandardId.size() > 0) {
					asrNo = qarNo + "-ASR";
					// 预留生成ASR检验单
					QualityAsrCheckForm qualityAsrCheckForm = new QualityAsrCheckForm();
					QualityAsrCheckFormEntity qualityAsrCheckFormEntity = new QualityAsrCheckFormEntity();
					qualityAsrCheckFormEntity.setAsrNumber(asrNo);
					qualityAsrCheckFormEntity.setQarNumber(qarNo);
					qualityAsrCheckFormEntity.setPartNumber(qualityQarBasicStandardEntity.getPartNumber());
					qualityAsrCheckFormEntity.setFormType(formType);
					qualityAsrCheckFormEntity.setProductModel(model);
					qualityAsrCheckFormEntity.setPartType(materialType);
					qualityAsrCheckFormEntity.setFoPoNumber(item.getInnerData().getPurchaseOrder());
					qualityAsrCheckFormEntity.setSupplierWorkshop(item.getInnerData().getVendor());
					qualityAsrCheckFormEntity.setPlanRemark(qualityQarBasicStandardEntity.getPlanRemark());
					DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
					qualityAsrCheckFormEntity.setQualityPlan(qualityQarBasicStandardEntity.getCreator() + " "
							+ df.format(qualityQarBasicStandardEntity.getCreationTime()));
					qualityAsrCheckFormEntity.setStatus(DataStatus.planning);
					qualityAsrCheckForm.setInnerData(qualityAsrCheckFormEntity);
					listQualityAsrCheckForm.add(qualityAsrCheckForm);
				}
				// 获取检验特性
				listQuqlityQarCheckItem = this.createQarCheckItem(qualityQarBasicStandardEntity.getId(), qarNo);
				// 创建QAR检验单
				item.getInnerData().setQarNo(qarNo);
				item.getInnerData().setNdtNo(ndtNo);
				item.getInnerData().setAsrNo(asrNo);
				item.getInnerData().setFormType(formType);
				item.getInnerData().setQarBasicStandardId(qualityQarBasicStandardEntity.getId());
				item.getInnerData().setCurrentStatus(MomConstants.QUALITY_QAR_CURRENT_STATUS_ISSUE);
				item.getInnerData().setChangedLetters(qualityQarBasicStandardEntity.getChangedLetters());
				item.getInnerData().setStandard(qualityQarBasicStandardEntity.getStatus());
				item.getInnerData().setRouteMaterialNumber(qualityQarBasicStandardEntity.getRouteMaterialNumber());
				item.getInnerData().setType(qualityQarBasicStandardEntity.getType());
				item.getInnerData().setCategory(qualityQarBasicStandardEntity.getCategory());
				item.getInnerData().setLevel(qualityQarBasicStandardEntity.getLevel());
				item.getInnerData().setShape(qualityQarBasicStandardEntity.getShape());
				item.getInnerData().setNorms(qualityQarBasicStandardEntity.getNorms());
				item.getInnerData().setMaterialType(qualityQarBasicStandardEntity.getMaterialType());
				item.getInnerData().setMaterialScience(qualityQarBasicStandardEntity.getManufacturer());
				item.getInnerData().setModel(qualityQarBasicStandardEntity.getModel());
				item.getInnerData().setAtpNo(qualityQarBasicStandardEntity.getAtpNumber());
				item.getInnerData().setSoftwareNo(qualityQarBasicStandardEntity.getSoftwareNumber());
				item.getInnerData().setSoftwareVersion(qualityQarBasicStandardEntity.getSoftwareRevision());
				item.getInnerData().setRequiredSize(qualityQarBasicStandardEntity.getRequiredSize());
				item.getInnerData().setSamplesQuantity(qualityQarBasicStandardEntity.getSamplesQuantity());
				item.getInnerData().setPlanRemark(qualityQarBasicStandardEntity.getPlanRemark());
				item.getInnerData().setPerformanceRequest(qualityQarBasicStandardEntity.getPerformanceRequirement());
				item.getInnerData().setStandard(qualityQarBasicStandardEntity.getStandard());
				item.getInnerData().setStandardVersion(qualityQarBasicStandardEntity.getStandardVersion());
				item.getInnerData().setFigureNo(qualityQarBasicStandardEntity.getDrawingNumber());
				item.getInnerData().setFigureVersion(qualityQarBasicStandardEntity.getDrawingRevision());

			}

		}
		// 保存实验数据到对应表中
		if (basicStandardRequirementList.size() > 0) {
			qualityPclrTestInvoiceDetailDataHandler.saveBatch(basicStandardRequirementList,
					basicStandardRequirementList.size());
		}
		// 保存pclr、NDT
		if (listQualityPclrTestInvoice != null && listQualityPclrTestInvoice.size() > 0) {
			ResultBean insertBatch = qualityPclrTestInvoiceDataHandler.batchInsertPclrData(listQualityPclrTestInvoice);
			if (!insertBatch.success) {
				throw new RuntimeException("插入PCLR实验单失败！");
			}
		}
		// 保存ASR
		if (listQualityAsrCheckForm != null && listQualityAsrCheckForm.size() > 0) {
			ResultBean batchInsertAsrCheckForm = qualityAsrCheckFormDataHandler
					.batchInsertAsrCheckForm(listQualityAsrCheckForm);
			if (!batchInsertAsrCheckForm.success) {
				throw new RuntimeException("插入ASR检验单失败！");
			}
		}
		// 保存检验特性
		if (listQuqlityQarCheckItem != null && listQuqlityQarCheckItem.size() > 0) {
			ResultBean insertBatch = quqlityQarCheckItemDataHandler.insertBatch(listQuqlityQarCheckItem);
			if (!insertBatch.success) {
				throw new RuntimeException("插入QAR检验特性失败！");
			}
		}
		ResultBean insertBatch = this.insertBatch(list);
		if (!insertBatch.success) {
			throw new RuntimeException("插入QAR检验单失败！");
		}
		// 修改QAR查询状态
		return resultBean;
	}

	/**
	 * 
	 * @param obj        入库单对象
	 * @param taskStatus qar生辰状态 1已生成 0 未生成
	 * @return
	 */
	public QualityQarTaskQuery createQualityQarTaskQuery(QualitySapPurchaseOrder obj, String taskStatus, String qarNo) {
		QualityQarTaskQuery qualityQarTaskQuery = new QualityQarTaskQuery();
		QualityQarTaskQueryEntity qualityQarTaskQueryEntity = new QualityQarTaskQueryEntity();
		qualityQarTaskQueryEntity.setQarNo(qarNo);
		qualityQarTaskQueryEntity.setPurchaseOrder(obj.getInnerData().getPurchaseOrder());
		qualityQarTaskQueryEntity.setPartNo(obj.getInnerData().getPaiHao());
		qualityQarTaskQueryEntity.setPartName(obj.getInnerData().getMaterialDescription());
		qualityQarTaskQueryEntity.setCaiLiaoXingShi(obj.getInnerData().getCaiLiaoXingShi());
		qualityQarTaskQueryEntity.setGuiFan(obj.getInnerData().getGuiFan());
		qualityQarTaskQueryEntity.setVendorBatchNumber(obj.getInnerData().getVendorBatchNumber());
		qualityQarTaskQueryEntity.setBatchNumber(obj.getInnerData().getSerialNumber());
		qualityQarTaskQueryEntity.setZpmCpmSpm(obj.getInnerData().getZpmCpmSpm());
		qualityQarTaskQueryEntity.setMaterial(obj.getInnerData().getMaterial());
		qualityQarTaskQueryEntity.setGuiGe(obj.getInnerData().getGuiGe());
		qualityQarTaskQueryEntity.setQuantity(obj.getInnerData().getQuantity().doubleValue());
		qualityQarTaskQueryEntity.setUom(obj.getInnerData().getBom());
		qualityQarTaskQueryEntity.setTaskStatus(MomConstants.QUALITY_QAR_QUERY_NOISSUED);// 未发布
		qualityQarTaskQueryEntity.setVendorName(obj.getInnerData().getVendorName());
		qualityQarTaskQueryEntity.setMaterialType(obj.getInnerData().getMaterialType());
		qualityQarTaskQuery.setInnerData(qualityQarTaskQueryEntity);
		return qualityQarTaskQuery;
	}

	// 通过母本查询对应检验特性数据，当查询出来后将对应检验特性数据春出道qar检验特性对应集合中，方便后面操作
	public List<QuqlityQarCheckItem> createQarCheckItem(long qualityQarBasicStandardId, String qarNo) {
		ArrayList<QuqlityQarCheckItem> listQuqlityQarCheckItem = new ArrayList<QuqlityQarCheckItem>();
		List<QualityQarBasicStandardCheck> selectByQarBasicStandardId2 = qualityQarBasicStandardCheckDataHandler
				.selectByQarBasicStandardId(qualityQarBasicStandardId);
		if (selectByQarBasicStandardId2 != null && selectByQarBasicStandardId2.size() > 0) {
			// 存在检验特性
			for (QualityQarBasicStandardCheck itemCheck : selectByQarBasicStandardId2) {
				QualityQarBasicStandardCheckEntity innerData2 = itemCheck.getInnerData();
				List<QualityQarBasicStandardCheckEntity> qarBasicStandardCheckItemList = itemCheck
						.getQarBasicStandardCheckList();
				if (innerData2 != null) {
					QuqlityQarCheckItem quqlityQarCheckItem = new QuqlityQarCheckItem();
					QuqlityQarCheckItemEntity quqlityQarCheckItemEntity = new QuqlityQarCheckItemEntity();
					quqlityQarCheckItemEntity.setQarNo(qarNo);
					quqlityQarCheckItemEntity.setCheckParentId(0);
					long groupId2 = innerData2.getGroupId();
					if (groupId2 != 0) {
						List<QualityAttachmentGroup> byAttachmentGroupId = qualityAttachmentGroupDataHandler
								.getByAttachmentGroupId(groupId2);
						for (QualityAttachmentGroup qualityAttachmentGroup : byAttachmentGroupId) {
							quqlityQarCheckItemEntity.setCheckPictureName(
									qualityAttachmentGroup.getQualityAttachment().getInnerData().getRealName());
							quqlityQarCheckItemEntity.setCheckPicturePath(
									qualityAttachmentGroup.getQualityAttachment().getInnerData().getFilePath());
							quqlityQarCheckItemEntity.setCheckItem(innerData2.getCheckItem());
							baseEntityDataUtil.setBaseEntityData(quqlityQarCheckItemEntity);
							quqlityQarCheckItemEntity.setAttachmentGroupId(groupId2);
							quqlityQarCheckItem.setInnerData(quqlityQarCheckItemEntity);
							listQuqlityQarCheckItem.add(quqlityQarCheckItem);
						}
					}
					// 子项
					if (qarBasicStandardCheckItemList != null && qarBasicStandardCheckItemList.size() > 0) {
						for (QualityQarBasicStandardCheckEntity itemCheckEntity : qarBasicStandardCheckItemList) {
							long groupId = itemCheckEntity.getGroupId();
							if (groupId != 0) {
								List<QualityAttachmentGroup> byAttachmentGroupId = qualityAttachmentGroupDataHandler
										.getByAttachmentGroupId(groupId);
								for (QualityAttachmentGroup qualityAttachmentGroup : byAttachmentGroupId) {
									QuqlityQarCheckItem quqlityQarCheckItem2 = new QuqlityQarCheckItem();
									QuqlityQarCheckItemEntity quqlityQarCheckItemEntity2 = new QuqlityQarCheckItemEntity();
									quqlityQarCheckItemEntity2.setAttachmentGroupId(groupId);
									quqlityQarCheckItemEntity2.setQarNo(qarNo);
									quqlityQarCheckItemEntity2.setCheckParentId(quqlityQarCheckItemEntity.getId());
									quqlityQarCheckItemEntity2.setCheckDetail(itemCheckEntity.getCheckDetail());
									quqlityQarCheckItemEntity2.setCheckPictureName(
											qualityAttachmentGroup.getQualityAttachment().getInnerData().getRealName());
									quqlityQarCheckItemEntity2.setCheckPicturePath(
											qualityAttachmentGroup.getQualityAttachment().getInnerData().getFilePath());
									baseEntityDataUtil.setBaseEntityData(quqlityQarCheckItemEntity2);
									quqlityQarCheckItem2.setInnerData(quqlityQarCheckItemEntity2);
									listQuqlityQarCheckItem.add(quqlityQarCheckItem2);
								}
							}
						}
					}
				}
			}
		}
		return listQuqlityQarCheckItem;
	}

	
	
	// 通过检验特性数据集合，将对应检验特性数据春出道qar检验特性对应集合中，方便后面操作
	public List<QuqlityQarCheckItem> getQarCheckItem(List<QualityQarBasicStandardCheck> selectByQarBasicStandardId2,
			String qarNo) {
		ArrayList<QuqlityQarCheckItem> listQuqlityQarCheckItem = new ArrayList<QuqlityQarCheckItem>();
		if (selectByQarBasicStandardId2 != null && selectByQarBasicStandardId2.size() > 0) {
			// 存在检验特性
			for (QualityQarBasicStandardCheck itemCheck : selectByQarBasicStandardId2) {
				QualityQarBasicStandardCheckEntity innerData2 = itemCheck.getInnerData();
				List<QualityQarBasicStandardCheckEntity> qarBasicStandardCheckItemList = itemCheck
						.getQarBasicStandardCheckList();
				if (innerData2 != null) {
					long generateId = idFactory.generateId();
					QuqlityQarCheckItem quqlityQarCheckItem = new QuqlityQarCheckItem();
					QuqlityQarCheckItemEntity quqlityQarCheckItemEntity = new QuqlityQarCheckItemEntity();
					quqlityQarCheckItemEntity.setQarNo(qarNo);
					quqlityQarCheckItemEntity.setCheckParentId(0);
					quqlityQarCheckItemEntity.setId(generateId);
					List<Long> attachmentIds = itemCheck.getInnerData().getAttachmentIds();
					if (!CollectionUtils.isEmpty(attachmentIds)) {
						long groupIdByAttachmentIds = qualityAttachmentGroupDataHandler.getGroupIdByAttachmentIds(attachmentIds, itemCheck.getInnerData().getCheckItem());
						itemCheck.getInnerData().setGroupId(groupIdByAttachmentIds);
					}
					quqlityQarCheckItemEntity.setCheckItem(innerData2.getCheckItem());
					baseEntityDataUtil.setNotNullBaseEntityData(quqlityQarCheckItemEntity);
					quqlityQarCheckItem.setInnerData(quqlityQarCheckItemEntity);
					listQuqlityQarCheckItem.add(quqlityQarCheckItem);
					// 子项
					if (qarBasicStandardCheckItemList != null && qarBasicStandardCheckItemList.size() > 0) {
						List<QuqlityQarCheckItem> itemDteilList = new ArrayList<QuqlityQarCheckItem>();
						quqlityQarCheckItem.setListItemDetails(itemDteilList);
						for (QualityQarBasicStandardCheckEntity itemCheckEntity : qarBasicStandardCheckItemList) {
							List<Long> attachmentIds2 = itemCheckEntity.getAttachmentIds();
							if (!CollectionUtils.isEmpty(attachmentIds2)) {
								long groupIdByAttachmentId = qualityAttachmentGroupDataHandler.getGroupIdByAttachmentIds(attachmentIds2, itemCheckEntity.getCheckDetail());
								QuqlityQarCheckItemEntity quqlityQarCheckItemEntity2 = new QuqlityQarCheckItemEntity();
								quqlityQarCheckItemEntity2.setQarNo(qarNo);
								quqlityQarCheckItemEntity2.setGroupId(groupIdByAttachmentId);
								quqlityQarCheckItemEntity2.setCheckParentId(generateId);
								quqlityQarCheckItemEntity2.setCheckDetail(itemCheckEntity.getCheckDetail());
								QuqlityQarCheckItem quqlityQarCheckItem2 = new QuqlityQarCheckItem();
								baseEntityDataUtil.setBaseEntityData(quqlityQarCheckItemEntity2);
								quqlityQarCheckItem2.setInnerData(quqlityQarCheckItemEntity2);
								quqlityQarCheckItem.getListItemDetails().add(quqlityQarCheckItem2);
							}
						}
					}
				}
			}
		}
		return listQuqlityQarCheckItem;
	}

	// 通过QAR编号获取QAR信息
	public QualityQarCheckInvoice getByQarNo(String qarNo) {
		QueryWrapper<QualityQarCheckInvoiceEntity> queryWrapper = new QueryWrapper<QualityQarCheckInvoiceEntity>();
		queryWrapper.eq("row_status", 1);
		queryWrapper.in("qar_no", qarNo);
		QualityQarCheckInvoiceEntity qarCheckInvoiceEntity = qualityQarCheckInvoiceDao.selectOne(queryWrapper);
		if (qarCheckInvoiceEntity == null) {
			return null;
		}
		QualityQarCheckInvoice qualityQarCheckInvoice = new QualityQarCheckInvoice();
		qualityQarCheckInvoice.setInnerData(qarCheckInvoiceEntity);
		// 检验特性
		List<QuqlityQarCheckItem> listQuqlityQarCheckItem = quqlityQarCheckItemDataHandler.getByQarNo(qarNo);
		qualityQarCheckInvoice.setListCheckItem(listQuqlityQarCheckItem);
		// PCLR信息
		ArrayList<QualityPclrTestInvoice> listPclrAndNdt = new ArrayList<QualityPclrTestInvoice>();
		if (qarCheckInvoiceEntity.getPclrNo() != null && !"".equals(qarCheckInvoiceEntity.getPclrNo())) {
			QueryWrapper<QualityPclrTestInvoiceEntity> queryWrapper1 = new QueryWrapper<QualityPclrTestInvoiceEntity>();
			queryWrapper1.eq("row_status", 1);
			queryWrapper1.eq("test_no", qarCheckInvoiceEntity.getPclrNo());
			queryWrapper1.eq("qar_no", qarNo);
			queryWrapper1.eq("test_type", "PCLR");
			QualityPclrTestInvoiceEntity selectOne = qualityPclrTestInvoiceDao.selectOne(queryWrapper1);
			if (selectOne != null) {
				QualityPclrTestInvoice qualityPclrTestInvoice = new QualityPclrTestInvoice();
				qualityPclrTestInvoice.setInnerData(selectOne);
				listPclrAndNdt.add(qualityPclrTestInvoice);
			}
		}
		// ndt
		if (qarCheckInvoiceEntity.getNdtNo() != null && !"".equals(qarCheckInvoiceEntity.getNdtNo())) {
			QueryWrapper<QualityPclrTestInvoiceEntity> queryWrapper1 = new QueryWrapper<QualityPclrTestInvoiceEntity>();
			queryWrapper1.eq("row_status", 1);
			queryWrapper1.eq("test_no", qarCheckInvoiceEntity.getNdtNo());
			queryWrapper1.eq("qar_no", qarNo);
			queryWrapper1.eq("test_type", "NDT");
			QualityPclrTestInvoiceEntity selectOne = qualityPclrTestInvoiceDao.selectOne(queryWrapper1);
			if (selectOne != null) {
				QualityPclrTestInvoice qualityPclrTestInvoice = new QualityPclrTestInvoice();
				qualityPclrTestInvoice.setInnerData(selectOne);
				listPclrAndNdt.add(qualityPclrTestInvoice);
			}
		}
		qualityQarCheckInvoice.setListPclr(listPclrAndNdt);

		// asr
		if (qarCheckInvoiceEntity.getAsrNo() != null && !"".equals(qarCheckInvoiceEntity.getAsrNo())) {
			QueryWrapper<QualityAsrCheckFormEntity> queryWrapper1 = new QueryWrapper<QualityAsrCheckFormEntity>();
			queryWrapper1.eq("row_status", 1);
			queryWrapper1.eq("asr_number", qarCheckInvoiceEntity.getAsrNo());
			queryWrapper1.eq("qar_number", qarNo);
			QualityAsrCheckFormEntity selectOne = qualityAsrCheckFormDao.selectOne(queryWrapper1);
			if (selectOne != null) {
				QualityAsrCheckForm qualityAsrCheckForm = new QualityAsrCheckForm();
				qualityAsrCheckForm.setInnerData(selectOne);
				qualityQarCheckInvoice.setAsrCheckForm(qualityAsrCheckForm);
			}
		}
		// 限制要求
		// 验证实验要求
		QueryWrapper<QualityPclrTestInvoiceDetailEntity> queryWrapper2 = new QueryWrapper<QualityPclrTestInvoiceDetailEntity>();
		queryWrapper2.eq("row_status", 1);
		queryWrapper2.eq("requirement_type", MomConstants.QUALITY_QAR_REQUIREMENT_TYPE_LIMIT);
		queryWrapper2.eq("qar_basic_standard_id", qarCheckInvoiceEntity.getId());
		List<QualityPclrTestInvoiceDetailEntity> selectList = qualityPclrTestInvoiceDetailDao.selectList(queryWrapper2);
		if (selectList != null && selectList.size() > 0) {
			ArrayList<QualityPclrTestInvoiceDetailBean> list = new ArrayList<QualityPclrTestInvoiceDetailBean>();
			for (QualityPclrTestInvoiceDetailEntity item : selectList) {
				QualityPclrTestInvoiceDetailBean qualityPclrTestInvoiceDetailBean = new QualityPclrTestInvoiceDetailBean();
				qualityPclrTestInvoiceDetailBean.setInnerData(item);
				list.add(qualityPclrTestInvoiceDetailBean);
			}
			qualityQarCheckInvoice.setListPclrTestRequirement(list);
		}
		// 当为纠正措施数据时将对应纠正措施数据查询出来在qar检验单中显示出来
		List<QualityQarVerifyPlanEntity> selectList2 = null;
		if (qarCheckInvoiceEntity.getIsVerify().equals("1")) {
			QueryWrapper<QualityQarVerifyPlanEntity> queryWrapper3 = new QueryWrapper<QualityQarVerifyPlanEntity>();
			queryWrapper3.eq("row_status", 1);
			queryWrapper3.eq("partno", qarCheckInvoiceEntity.getPartNo());
			selectList2 = qualityQarVerifyPlanDao.selectList(queryWrapper3);
		}
		List<QualityQarVerifyPlanBean> QarVerifyPlanBeanList = new ArrayList<QualityQarVerifyPlanBean>();
		if (selectList2 != null) {
			for (QualityQarVerifyPlanEntity qualityQarVerifyPlanEntity : selectList2) {
				QualityQarVerifyPlanBean qualityQarVerifyPlanBean = new QualityQarVerifyPlanBean();
				qualityQarVerifyPlanBean.setInnerData(qualityQarVerifyPlanEntity);
				QarVerifyPlanBeanList.add(qualityQarVerifyPlanBean);
			}
		}
		qualityQarCheckInvoice.setQarVerifyPlanBeanList(QarVerifyPlanBeanList);
		
		// 当为限售件数据时，将对应限售件数据查询出来
		List<QarRestrictedPart> byQarNo = qarRestrictedPartDataHandler.getByQarNo(qarNo);
		qualityQarCheckInvoice.setRestrictedPartList(byQarNo);
		// 附件

		return qualityQarCheckInvoice;
	}

	// 发布
	public ResultBean qarIssue(QualityQarCheckInvoice obj) {
		ResultBean resultBean = new ResultBean(true);
		if (obj == null || obj.getInnerData() == null) {
			resultBean.setErrorMessge("数据为空");
			return resultBean;
		}
		String currentStatus = obj.getInnerData().getCurrentStatus();
		if (currentStatus == null || !currentStatus.equals(MomConstants.QUALITY_QAR_CURRENT_STATUS_STAYISSUED)) {
			resultBean.setErrorMessge("只有待发布状态的QAR才能进行发布");
			return resultBean;
		}
		QueryWrapper<QualityQarCheckInvoiceEntity> queryWrapper = new QueryWrapper<QualityQarCheckInvoiceEntity>();
		queryWrapper.eq("row_status", 1);
		queryWrapper.eq("qar_no", obj.getInnerData().getQarNo());
		QualityQarCheckInvoiceEntity selectOne = qualityQarCheckInvoiceDao.selectOne(queryWrapper);
		if (selectOne == null) {
			resultBean.setErrorMessge("QAR信息不存在");
			return resultBean;
		}
		selectOne.setCurrentStatus(MomConstants.QUALITY_QAR_CURRENT_STATUS_ISSUE);
		selectOne.setPlanUser(obj.getInnerData().getPlanUser());// 质量计划人员信息
		selectOne.setPlanDate(TimeUtil.getLocalDate());
		baseEntityDataUtil.updateBaseEntityData(selectOne);
		int updateById = qualityQarCheckInvoiceDao.updateById(selectOne);
		// 当qar状态改变将数据改变发送给来料检验系统
		conditionalSentMaterielReceive.setQarStatus(selectOne.getQarNo(), selectOne.getCurrentStatus());

		if (updateById < 1) {
			resultBean.setErrorMessge("QAR发布失败");
			return resultBean;
		}
		return resultBean;
	}

	// 开始检验
	public ResultBean beginCheck(QualityQarCheckInvoice obj) {
		ResultBean resultBean = new ResultBean(true);
		if (obj == null || obj.getInnerData() == null) {
			resultBean.setErrorMessge("数据为空");
			return resultBean;
		}
		String currentStatus = obj.getInnerData().getCurrentStatus();
		if (currentStatus == null || !currentStatus.equals(MomConstants.QUALITY_QAR_CURRENT_STATUS_ISSUE)) {
			resultBean.setErrorMessge("只有已发布状态的QAR才能进行当前操作");
			return resultBean;
		}
		QueryWrapper<QualityQarCheckInvoiceEntity> queryWrapper = new QueryWrapper<QualityQarCheckInvoiceEntity>();
		queryWrapper.eq("row_status", 1);
		queryWrapper.eq("qar_no", obj.getInnerData().getQarNo());
		QualityQarCheckInvoiceEntity selectOne = qualityQarCheckInvoiceDao.selectOne(queryWrapper);
		if (selectOne == null) {
			resultBean.setErrorMessge("QAR信息不存在");
			return resultBean;
		}
		selectOne.setCurrentStatus(MomConstants.QUALITY_QAR_CURRENT_STATUS_CHECKING);// 检验中
		selectOne.setCheckUser(baseEntityDataUtil.getCurrentUser());
		selectOne.setCheckUserNo(baseEntityDataUtil.getJobNumber());
		// 质量检验人员信息
		selectOne.setCheckDate(TimeUtil.getLocalDate());
		baseEntityDataUtil.updateBaseEntityData(selectOne);
		int updateById = qualityQarCheckInvoiceDao.updateById(selectOne);
		// 当qar状态改变将状态改变发送给来料检验系统
		conditionalSentMaterielReceive.setQarStatus(selectOne.getQarNo(), selectOne.getCurrentStatus());

		if (updateById < 1) {
			resultBean.setErrorMessge("QAR开始检验失败");
			return resultBean;
		}
		// 添加检验人信息到QAR查询表中
		QueryWrapper<QualityQarTaskQueryEntity> queryWrapper2 = new QueryWrapper<QualityQarTaskQueryEntity>();
		queryWrapper2.eq("row_status", 1);
		queryWrapper2.eq("qar_no", obj.getInnerData().getQarNo());
		QualityQarTaskQueryEntity taskQueryEntity = qualityQarTaskQueryDao.selectOne(queryWrapper2);
		if (taskQueryEntity == null) {
			throw new RuntimeException("无法获取QAR查询信息");
		}
		taskQueryEntity.setTaskExecutor(obj.getInnerData().getCheckUser());
		taskQueryEntity.setExecutorJobNumber(obj.getInnerData().getCheckUserNo());
		baseEntityDataUtil.updateBaseEntityData(taskQueryEntity);
		int updateById2 = qualityQarTaskQueryDao.updateById(taskQueryEntity);
		if (updateById2 < 1) {
			throw new RuntimeException("任务领取失败");
		}
		return resultBean;
	}

	// 驳回
	public ResultBean qarReject(QualityQarCheckInvoice obj) {
		ResultBean resultBean = new ResultBean(true);
		if (obj == null || obj.getInnerData() == null) {
			resultBean.setErrorMessge("数据为空");
			return resultBean;
		}
		QueryWrapper<QualityQarCheckInvoiceEntity> queryWrapper = new QueryWrapper<QualityQarCheckInvoiceEntity>();
		queryWrapper.eq("row_status", 1);
		queryWrapper.eq("qar_no", obj.getInnerData().getQarNo());
		QualityQarCheckInvoiceEntity selectOne = qualityQarCheckInvoiceDao.selectOne(queryWrapper);
		if (selectOne == null) {
			resultBean.setErrorMessge("QAR信息不存在");
			return resultBean;
		}
		String currentStatusNow = obj.getInnerData().getCurrentStatus();
		String currentStatusOld = selectOne.getCurrentStatus();

		if (Integer.valueOf(currentStatusNow).intValue() > Integer.valueOf(currentStatusOld).intValue()) {
			resultBean.setErrorMessge("驳回状态不能高于当前状态");
			return resultBean;
		}
		// 当前状态为检验中，驳回至发布中或者待发布中，清空检验人信息
		if (currentStatusOld.equals(MomConstants.QUALITY_QAR_CURRENT_STATUS_CHECKING)) {
			selectOne.setCheckUser("");
			selectOne.setCheckUserNo("");
			// 如果驳回至发布或者待发布，清空查询表检验人员信息
			QueryWrapper<QualityQarTaskQueryEntity> queryWrapper2 = new QueryWrapper<QualityQarTaskQueryEntity>();
			queryWrapper2.eq("row_status", 1);
			queryWrapper2.eq("qar_no", obj.getInnerData().getQarNo());
			QualityQarTaskQueryEntity taskQueryEntity = qualityQarTaskQueryDao.selectOne(queryWrapper2);
			if (taskQueryEntity == null) {
				throw new RuntimeException("无法获取QAR查询信息");
			}
			taskQueryEntity.setTaskExecutor("");
			taskQueryEntity.setExecutorJobNumber("");
			baseEntityDataUtil.updateBaseEntityData(taskQueryEntity);
			int updateById = qualityQarTaskQueryDao.updateById(taskQueryEntity);
			if (updateById < 1) {
				throw new RuntimeException("QAR驳回失败");
			}
		}
		selectOne.setCurrentStatus(currentStatusNow);
		baseEntityDataUtil.updateBaseEntityData(selectOne);
		int updateById = qualityQarCheckInvoiceDao.updateById(selectOne);

		// 当qar状态改变将数据改变发送给来料检验系统
		conditionalSentMaterielReceive.setQarStatus(selectOne.getQarNo(), selectOne.getCurrentStatus());
		if (updateById < 1) {
			resultBean.setErrorMessge("QAR驳回失败");
			return resultBean;
		}
		QualityReject qualityReject = obj.getQualityReject();
		if (qualityReject == null || qualityReject.getInnerData() == null) {
			throw new RuntimeException("驳回历史信息为空！");
		}
		ResultBean insert = qualityRejectDataHandler.insert(qualityReject);
		if (!insert.success) {
			throw new RuntimeException(insert.getMessage());
		}

		return resultBean;
	}

	// 作废
	public ResultBean qarDisabled(QualityQarCheckInvoice obj) {
		ResultBean resultBean = new ResultBean(true);
		if (obj == null || obj.getInnerData() == null) {
			resultBean.setErrorMessge("数据为空");
			return resultBean;
		}
		QueryWrapper<QualityQarCheckInvoiceEntity> queryWrapper = new QueryWrapper<QualityQarCheckInvoiceEntity>();
		queryWrapper.eq("row_status", 1);
		queryWrapper.eq("qar_no", obj.getInnerData().getQarNo());
		QualityQarCheckInvoiceEntity selectOne = qualityQarCheckInvoiceDao.selectOne(queryWrapper);
		if (selectOne == null) {
			resultBean.setErrorMessge("QAR信息不存在");
			return resultBean;
		}
		selectOne.setCurrentStatus(MomConstants.QUALITY_QAR_CURRENT_STATUS_DISABLED);// 作废
		baseEntityDataUtil.updateBaseEntityData(selectOne);
		int updateById = qualityQarCheckInvoiceDao.updateById(selectOne);

		// 当qar状态改变将数据改变发送给来料检验系统
		conditionalSentMaterielReceive.setQarStatus(selectOne.getQarNo(), selectOne.getCurrentStatus());
		if (updateById < 1) {
			resultBean.setErrorMessge("作废失败");
			return resultBean;
		}
		// PCLR信息
		ArrayList<QualityPclrTestInvoice> listPclrAndNdt = new ArrayList<QualityPclrTestInvoice>();
		if (selectOne.getPclrNo() != null && !"".equals(selectOne.getPclrNo())) {
			QueryWrapper<QualityPclrTestInvoiceEntity> queryWrapper1 = new QueryWrapper<QualityPclrTestInvoiceEntity>();
			queryWrapper1.eq("row_status", 1);
			queryWrapper1.eq("test_no", selectOne.getPclrNo());
			queryWrapper1.eq("qar_no", selectOne.getQarNo());
			queryWrapper1.eq("test_type", "PCLR");
			QualityPclrTestInvoiceEntity selectOne2 = qualityPclrTestInvoiceDao.selectOne(queryWrapper1);
			if (selectOne2 != null) {
				selectOne2.setStatus(MomConstants.QUALITY_PCLR_STATUS_DISABLED);// 作废
				QualityPclrTestInvoice qualityPclrTestInvoice = new QualityPclrTestInvoice();
				qualityPclrTestInvoice.setInnerData(selectOne2);
				listPclrAndNdt.add(qualityPclrTestInvoice);
			}
		}
		// ndt
		if (selectOne.getNdtNo() != null && !"".equals(selectOne.getNdtNo())) {
			QueryWrapper<QualityPclrTestInvoiceEntity> queryWrapper1 = new QueryWrapper<QualityPclrTestInvoiceEntity>();
			queryWrapper1.eq("row_status", 1);
			queryWrapper1.eq("test_no", selectOne.getNdtNo());
			queryWrapper1.eq("qar_no", selectOne.getQarNo());
			queryWrapper1.eq("test_type", "NDT");
			QualityPclrTestInvoiceEntity selectOne3 = qualityPclrTestInvoiceDao.selectOne(queryWrapper1);
			if (selectOne3 != null) {
				selectOne3.setStatus(MomConstants.QUALITY_PCLR_STATUS_DISABLED);// 作废
				QualityPclrTestInvoice qualityPclrTestInvoice = new QualityPclrTestInvoice();
				qualityPclrTestInvoice.setInnerData(selectOne3);
				listPclrAndNdt.add(qualityPclrTestInvoice);
			}
		}
		if (listPclrAndNdt != null && listPclrAndNdt.size() > 0) {
			// 修改pclr或者NDT状态为作废
			ResultBean resultBean2 = qualityPclrTestInvoiceDataHandler.updateStatusBatch(listPclrAndNdt);
			if (!resultBean2.success) {
				throw new RuntimeException(resultBean2.getMessage());
			}
		}
		// asr
		if (selectOne.getAsrNo() != null && !"".equals(selectOne.getAsrNo())) {
			QueryWrapper<QualityAsrCheckFormEntity> queryWrapper1 = new QueryWrapper<QualityAsrCheckFormEntity>();
			queryWrapper1.eq("row_status", 1);
			queryWrapper1.eq("asr_number", selectOne.getAsrNo());
			queryWrapper1.eq("qar_number", selectOne.getQarNo());
			QualityAsrCheckFormEntity selectOne3 = qualityAsrCheckFormDao.selectOne(queryWrapper1);
			if (selectOne3 != null) {
				selectOne3.setStatus(DataStatus.disabled);// 作废
				baseEntityDataUtil.updateBaseEntityData(selectOne3);
				int updateById2 = qualityAsrCheckFormDao.updateById(selectOne3);
				if (updateById2 < 1) {
					throw new RuntimeException("ASR作废失败");
				}
			}
		}
		return resultBean;
	}

	// 提交委托
	public ResultBean qarEntrust(QualityQarCheckInvoice obj) {
		ResultBean resultBean = new ResultBean(true);
		if (obj == null || obj.getInnerData() == null) {
			resultBean.setErrorMessge("数据为空");
			return resultBean;
		}
		QueryWrapper<QualityQarCheckInvoiceEntity> queryWrapper = new QueryWrapper<QualityQarCheckInvoiceEntity>();
		queryWrapper.eq("row_status", 1);
		queryWrapper.eq("qar_no", obj.getInnerData().getQarNo());
		QualityQarCheckInvoiceEntity selectOne = qualityQarCheckInvoiceDao.selectOne(queryWrapper);
		if (selectOne == null) {
			resultBean.setErrorMessge("QAR信息不存在");
			return resultBean;
		}
		selectOne.setCurrentStatus(MomConstants.QUALITY_QAR_CURRENT_STATUS_ENTRUST);// 委托中
		baseEntityDataUtil.updateBaseEntityData(selectOne);
		int updateById = qualityQarCheckInvoiceDao.updateById(selectOne);
		// 当qar状态改变将数据改变发送给来料检验系统
		conditionalSentMaterielReceive.setQarStatus(selectOne.getQarNo(), selectOne.getCurrentStatus());

		if (updateById < 1) {
			resultBean.setErrorMessge("QAR委托失败");
			return resultBean;
		}
		return resultBean;
	}

	// 提交审核
	public ResultBean qarAudit(QualityQarCheckInvoice obj) {
		ResultBean resultBean = new ResultBean(true);
		if (obj == null || obj.getInnerData() == null) {
			resultBean.setErrorMessge("数据为空");
			return resultBean;
		}
		QueryWrapper<QualityQarCheckInvoiceEntity> queryWrapper = new QueryWrapper<QualityQarCheckInvoiceEntity>();
		queryWrapper.eq("row_status", 1);
		queryWrapper.eq("qar_no", obj.getInnerData().getQarNo());
		QualityQarCheckInvoiceEntity selectOne = qualityQarCheckInvoiceDao.selectOne(queryWrapper);
		if (selectOne == null) {
			resultBean.setErrorMessge("QAR信息不存在");
			return resultBean;
		}
		selectOne.setCurrentStatus(MomConstants.QUALITY_QAR_CURRENT_STATUS_COMPLETE);// 检验完成
		// 通过qar查询来料检验表，当来料检验表有数据表示该qar已经被标记为来料检验qar
		// 此时调用接口通过PI_id查询PI状态是否为已关闭，当不是已关闭将不能提交审核
		QueryWrapper<QualityQarConditionalSentMaterielEntity> queryWrapper2 = new QueryWrapper<QualityQarConditionalSentMaterielEntity>();
		queryWrapper2.eq("qar_number", selectOne.getQarNo());
		QualityQarConditionalSentMaterielEntity selectOne2 = qualityQarConditionalSentMaterielDao
				.selectOne(queryWrapper2);
		if (selectOne2 != null) {
			Map<String, Object> selectpiIdStatusBypiId = conditionalSentMaterielReceive
					.selectpiIdStatusBypiId(selectOne2.getPiId());
			String status = selectpiIdStatusBypiId.get("PiStatus").toString();
			if (!status.equals("已关闭")) {
				resultBean.setErrorMessge("来料检验PI状态 " + status + " 为非关闭状态，无法提交审核");
				return resultBean;
			}
		}
		baseEntityDataUtil.updateBaseEntityData(selectOne);
		int updateById = qualityQarCheckInvoiceDao.updateById(selectOne);
		// 当qar状态改变将数据改变发送给来料检验系统
		conditionalSentMaterielReceive.setQarStatus(selectOne.getQarNo(), selectOne.getCurrentStatus());

		if (updateById < 1) {
			resultBean.setErrorMessge("提交审核失败");
			return resultBean;
		}
		return resultBean;
	}

	// 归档
	public ResultBean qarToFile(QualityQarCheckInvoice obj) {
		ResultBean resultBean = new ResultBean(true);
		if (obj == null || obj.getInnerData() == null) {
			resultBean.setErrorMessge("数据为空");
			return resultBean;
		}
		QueryWrapper<QualityQarCheckInvoiceEntity> queryWrapper = new QueryWrapper<QualityQarCheckInvoiceEntity>();
		queryWrapper.eq("row_status", 1);
		queryWrapper.eq("qar_no", obj.getInnerData().getQarNo());
		QualityQarCheckInvoiceEntity selectOne = qualityQarCheckInvoiceDao.selectOne(queryWrapper);
		if (selectOne == null) {
			resultBean.setErrorMessge("QAR信息不存在");
			return resultBean;
		}
		selectOne.setCurrentStatus(MomConstants.QUALITY_QAR_CURRENT_STATUS_TOFILE);// 归档
		baseEntityDataUtil.updateBaseEntityData(selectOne);
		int updateById = qualityQarCheckInvoiceDao.updateById(selectOne);
		// 当qar状态改变将数据改变发送给来料检验系统
		conditionalSentMaterielReceive.setQarStatus(selectOne.getQarNo(), selectOne.getCurrentStatus());

		// 调用回传接口将信息回传SAP

		if (updateById < 1) {
			resultBean.setErrorMessge("提交归档失败");
			return resultBean;
		}
		return resultBean;
	}

	// 修改保存
	public ResultBean update(QualityQarCheckInvoice obj) {
		ResultBean resultBean = new ResultBean(true);
		if (obj == null || obj.getInnerData() == null) {
			resultBean.setErrorMessge("数据为空");
			return resultBean;
		}
		QualityQarCheckInvoiceEntity innerData = obj.getInnerData();
		List<QualityAttachmentGroup> listAttachmentGroup = obj.getListAttachmentGroup();
		// 保存附件组数据
		if (listAttachmentGroup != null && listAttachmentGroup.size() > 0) {
			long attachmentGroupId = innerData.getAttachmentGroupId();
			if (attachmentGroupId == 0) {
				long id = idFactory.generateId();
				innerData.setAttachmentGroupId(id);
				for (QualityAttachmentGroup item : listAttachmentGroup) {
					item.getInnerData().setGroupId(id);
				}
			} else {
				for (QualityAttachmentGroup item : listAttachmentGroup) {
					item.getInnerData().setGroupId(attachmentGroupId);
				}
			}
			ResultBean resultBean2 = qualityAttachmentGroupDataHandler.insertBatch(listAttachmentGroup);
			if (!resultBean2.success) {
				throw new RuntimeException("保存附件组信息失败");
			}
		}
		
		// 更新检验特性数据
		List<QuqlityQarCheckItem> listCheckItem = obj.getListCheckItem();
		if (listCheckItem != null && listCheckItem.size() > 0) {
			quqlityQarCheckItemDataHandler.updateCheckItemData(listCheckItem, innerData.getQarNo());
		}
		
		
		
		// 更新限制要求数据
		List<QualityPclrTestInvoiceDetailBean> listStandardRequirement = obj.getListPclrTestRequirement();
		if (listStandardRequirement != null && listStandardRequirement.size() > 0) {
			// 查询对应qar检验单上对应的限制要求数据
			QueryWrapper<QualityPclrTestInvoiceDetailEntity> queryWrapper = new QueryWrapper<QualityPclrTestInvoiceDetailEntity>();
			queryWrapper.eq("row_status", 1);
			queryWrapper.eq("qar_basic_standard_id", innerData.getId());
			queryWrapper.eq("requirement_type", MomConstants.QUALITY_QAR_REQUIREMENT_TYPE_LIMIT);
			List<QualityPclrTestInvoiceDetailEntity> selectList = qualityPclrTestInvoiceDetailDao
					.selectList(queryWrapper);
			ArrayList<QualityPclrTestInvoiceDetailEntity> deleteList = new ArrayList<QualityPclrTestInvoiceDetailEntity>();
			ArrayList<QualityPclrTestInvoiceDetailEntity> addList = new ArrayList<QualityPclrTestInvoiceDetailEntity>();
			// 当查询的的限制要求数据中有查询不到新定义的限制要求数据，存入待删除集合
			for (QualityPclrTestInvoiceDetailEntity qualityQarBasicStandardRequirementEntity : selectList) {
				boolean flag = true;
				for (QualityPclrTestInvoiceDetailBean qualityQarBasicStandardRequirement : listStandardRequirement) {
					// 过滤出所有待删除的数据集合
					if (qualityQarBasicStandardRequirementEntity.getRequirementName()
							.equals(qualityQarBasicStandardRequirement.getInnerData().getRequirementName())) {
						flag = false;
					}
				}
				if (flag) {
					deleteList.add(qualityQarBasicStandardRequirementEntity);
				}
			}

			// 当新定义的的限制要求数据中有查询不到查询的限制要求数据，存入待新增集合
			for (QualityPclrTestInvoiceDetailBean qualityQarBasicStandardRequirement : listStandardRequirement) {
				boolean flag = true;
				for (QualityPclrTestInvoiceDetailEntity qualityQarBasicStandardRequiremententity : selectList) {
					// 过滤出所有待删除的数据集合
					if (qualityQarBasicStandardRequiremententity.getRequirementName()
							.equals(qualityQarBasicStandardRequirement.getInnerData().getRequirementName())) {
						flag = false;
					}
				}
				if (flag) {
					QualityPclrTestInvoiceDetailEntity innerData2 = qualityQarBasicStandardRequirement.getInnerData();
					QualityPclrTestInvoiceDetailEntity detailEntity = new QualityPclrTestInvoiceDetailEntity();
					detailEntity.setAircraftLimit(innerData2.getAircraftLimit());
					detailEntity.setMatNumber(innerData2.getMatNumber());
					detailEntity.setOther(innerData2.getOther());
					detailEntity.setQarBasicStandardId(innerData.getId());
					detailEntity.setRemark(innerData2.getRemark());
					detailEntity.setRequirementName(innerData2.getRequirementName());
					detailEntity.setRequirementType(innerData2.getRequirementType());
					detailEntity.setRowStatus(1);
					detailEntity.setTestItemQuatity(innerData2.getTestItemQuatity());
					baseEntityDataUtil.setBaseEntityData(detailEntity);
					addList.add(detailEntity);
				}
			}

			if (deleteList.size() > 0) {
				deleteList.forEach(item -> {
					item.setRowStatus(2);
					baseEntityDataUtil.updateBaseEntityData(item);
				});
				qualityPclrTestInvoiceDetailDataHandler.updateBatchById(deleteList, deleteList.size());
			}
			if (addList.size() > 0) {
				addList.forEach(item -> {
					item.setRowStatus(1);
					item.setQarBasicStandardId(innerData.getId());
					item.setRequirementType(MomConstants.QUALITY_QAR_REQUIREMENT_TYPE_LIMIT);
					baseEntityDataUtil.setBaseEntityData(item);
				});
				qualityPclrTestInvoiceDetailDataHandler.saveBatch(addList, addList.size());
			}
		}

		// 限售件数据保存,更新限售数据
		List<QarRestrictedPart> restrictedPartList = obj.getRestrictedPartList();
		if (restrictedPartList != null && restrictedPartList.size() > 0) {
			qarRestrictedPartDataHandler.batchUpdateData(restrictedPartList);
		}
		
		baseEntityDataUtil.updateBaseEntityData(innerData);
		int updateById = qualityQarCheckInvoiceDao.updateById(innerData);
		if (updateById < 1) {
			throw new RuntimeException("QAR修改保存失败");
		}
		return resultBean;
	}

	// 拆分
	public ResultBean qarSplit(QualityQarSplitBean obj) {
		ResultBean resultBean = new ResultBean(true);
		if (obj == null) {
			resultBean.setErrorMessge("数据为空");
			return resultBean;
		}
		String qarNo = obj.getQarNo();
		BigDecimal newQty = obj.getNewQty();
		String newSerialNumber = obj.getNewSerialNumber();
		BigDecimal splitQty = obj.getSplitQty();
		String splitSerialNumber = obj.getSplitSerialNumber();
		String splitUser = obj.getSplitUser();
		QualityQarCheckInvoice byQarNo = this.getByQarNo(qarNo);
		if (byQarNo == null || byQarNo.getInnerData() == null) {
			resultBean.setErrorMessge("QAR信息不存在");
			return resultBean;
		}
		QualityQarCheckInvoiceEntity innerData = byQarNo.getInnerData();
		innerData.setQuantity(newQty);
		innerData.setSerialNumber(newSerialNumber);
		innerData.setSplitUser(splitUser);
		innerData.setSplitDate(TimeUtil.getLocalDate());
		int updateById = qualityQarCheckInvoiceDao.updateById(innerData);
		if (updateById < 1) {
			resultBean.setErrorMessge("QAR拆分保存失败");
			return resultBean;
		}
		String year = String.valueOf(LocalDateTime.now().getYear());
		// 获取QAR流水号
		String qarSerialNumber = universalNumberGenerationDataHandler.getQarSerialNumber(year);
		String newQarNo = qarNo.substring(6) + year.substring(year.length() - 2) + "-" + qarSerialNumber;

		String pclrNo = "";
		String ndtNo = "";
		String asrNo = "";
		innerData.setQarNo(newQarNo);
		if (innerData.getPclrNo() != null && !"".equals(innerData.getPclrNo())) {
			pclrNo = newQarNo + "PCLR";
		}
		innerData.setPclrNo(pclrNo);
		if (innerData.getNdtNo() != null && !"".equals(innerData.getNdtNo())) {
			ndtNo = newQarNo + "NDT";
		}
		innerData.setNdtNo(ndtNo);
		if (innerData.getAsrNo() != null && !"".equals(innerData.getAsrNo())) {
			asrNo = newQarNo + "ASR";
		}
		innerData.setAsrNo(asrNo);
		innerData.setQuantity(splitQty);
		innerData.setSerialNumber(splitSerialNumber);
		baseEntityDataUtil.setBaseEntityData(innerData);
		// 保存拆分的qar
		int insert = qualityQarCheckInvoiceDao.insert(innerData);
		if (insert < 1) {
			throw new RuntimeException("QAR拆分失败");
		}
		// 保存pclr、ndt
		List<QualityPclrTestInvoice> pclr = byQarNo.getListPclr();
		if (pclr != null && pclr.size() > 0) {
			for (QualityPclrTestInvoice item : pclr) {
				if (item.getInnerData().getTestType().equals("PCLR")) {
					item.getInnerData().setTestNo(pclrNo);
					item.getInnerData().setQarNo(newQarNo);
				} else if (item.getInnerData().getTestType().equals("NDT")) {
					item.getInnerData().setTestNo(ndtNo);
					item.getInnerData().setQarNo(newQarNo);
				}
			}
			ResultBean insertBatch = qualityPclrTestInvoiceDataHandler.insertBatch(pclr);
			if (!insertBatch.success) {
				throw new RuntimeException("插入PCLR实验单失败！");
			}
		}
		// 保存asr
		QualityAsrCheckForm asrCheckForm = byQarNo.getAsrCheckForm();
		if (asrCheckForm != null) {
			asrCheckForm.getInnerData().setAsrNumber(asrNo);
			asrCheckForm.getInnerData().setQarNumber(newQarNo);
			ArrayList<QualityAsrCheckForm> list = new ArrayList<QualityAsrCheckForm>();
			ResultBean batchInsertAsrCheckForm = qualityAsrCheckFormDataHandler.batchInsertAsrCheckForm(list);
			if (!batchInsertAsrCheckForm.success) {
				throw new RuntimeException("插入ASR检验单失败！");
			}
		}
		// 保存检验特性
		List<QuqlityQarCheckItem> listCheckItem = byQarNo.getListCheckItem();
		if (listCheckItem != null && listCheckItem.size() > 0) {
			ArrayList<QuqlityQarCheckItem> listNew = new ArrayList<QuqlityQarCheckItem>();
			for (QuqlityQarCheckItem item : listCheckItem) {
				QuqlityQarCheckItemEntity innerData2 = item.getInnerData();
				List<QuqlityQarCheckItem> listItemDetails = item.getListItemDetails();
				if (innerData2 != null) {
					innerData2.setQarNo(newQarNo);
					baseEntityDataUtil.setBaseEntityData(innerData2);
					listNew.add(item);
					if (listItemDetails != null && listItemDetails.size() > 0) {
						for (QuqlityQarCheckItem item2 : listItemDetails) {
							if (item2.getInnerData() != null) {
								item2.getInnerData().setQarNo(newQarNo);
								item2.getInnerData().setCheckParentId(innerData2.getId());
								listNew.add(item2);
							}
						}
					}
				}
			}
			ResultBean insertBatch = quqlityQarCheckItemDataHandler.insertBatch(listNew);
			
			// 保存拆分后的限售件数据
			// 拆分时会将序列号拆出来，这时只需要找到那个序列号被拆出来了，并将拆出来以后的序列号对应的限售件数据的qar编号更新成拆出来的qar编号就好了
			
			List<QarRestrictedPartEntity> restrictedPartList = byQarNo.getRestrictedPartList().stream().map(a -> a.getInnerData()).collect(Collectors.toList());
			if (!CollectionUtils.isEmpty(byQarNo.getRestrictedPartList())) {
				List<QarRestrictedPartEntity> restrictedPartUpdatelist = new ArrayList<QarRestrictedPartEntity>();
				for (QarRestrictedPartEntity qarRestrictedPartEntity : restrictedPartList) {
					// 当拆分出来的序列号匹配到限售件的序列号
					if (splitSerialNumber.indexOf(qarRestrictedPartEntity.getRestrictedSerialNumber()) > 0) {
						qarRestrictedPartEntity.setQarNo(newQarNo);
						baseEntityDataUtil.updateBaseEntityData(qarRestrictedPartEntity);
						restrictedPartUpdatelist.add(qarRestrictedPartEntity);
					}
				}
				qarRestrictedPartDataHandler.batchInsertData(restrictedPartUpdatelist);
			}
			
			if (!insertBatch.success) {
				throw new RuntimeException("插入QAR检验特性失败！");
			}
		}
		return resultBean;
	}

	public QualityQarSelectReturnBean selectByFieldsForWeb(QualityQarSelectBean obj) {
		if (obj == null) {
			throw new RuntimeException("查询数据为空");
		}
		List<QualityQarSelectResultBean> selectByFieldsForWeb = qualityQarCheckInvoiceDao.selectByFieldsForWeb(obj);
		if (selectByFieldsForWeb == null || selectByFieldsForWeb.size() < 1) {
			return null;
		}
		int count = qualityQarCheckInvoiceDao.selectCountByFieldsForWeb(obj);
		QualityQarSelectReturnBean qualityQarSelectReturnBean = new QualityQarSelectReturnBean();
		qualityQarSelectReturnBean.setCount(count);
		qualityQarSelectReturnBean.setQar(selectByFieldsForWeb);
		return qualityQarSelectReturnBean;
	}

	// 通过qar编号查询qar检验表信息
	public QualityQarCheckInvoiceEntity selectByQarNumber(String qarNumber) {
		QueryWrapper<QualityQarCheckInvoiceEntity> queryWrapper = new QueryWrapper<QualityQarCheckInvoiceEntity>();
		queryWrapper.eq("qar_no", qarNumber);
		QualityQarCheckInvoiceEntity selectOne = qualityQarCheckInvoiceDao.selectOne(queryWrapper);
		return selectOne;
	}

	/**
	 * 在qar检验单提交审核之前，如果母本升版完成，那么将对应的限制要求和检验验证特性数据对应更改
	 * 
	 * @throws CloneNotSupportedException
	 **/
	public void upgradeUpdateQarData(List<QualityQarBasicStandardCheck> basicStandardCheckList,
			List<QualityQarBasicStandardRequirement> basicStandardRequirement, long qualityQarBasicStandardId,QualityQarBasicStandardEntity qualityQarBasicStandardEntity) {
//		ResultBean insertBatch = quqlityQarCheckItemDataHandler.insertBatch(listQuqlityQarCheckItem);
		// 检验验证特性数据集合
		ArrayList<QuqlityQarCheckItem> checkItemList = new ArrayList<QuqlityQarCheckItem>();
		// 查询qar中对应母本的已下发，检验中，委托中的数据
		QueryWrapper<QualityQarCheckInvoiceEntity> queryWrapper = new QueryWrapper<QualityQarCheckInvoiceEntity>();
		queryWrapper.eq("qar_basic_standard_id", qualityQarBasicStandardId);
		queryWrapper.eq("row_status", 1);
		// 只查询已发布，检验中，委托中三个状态数据
		queryWrapper.in("current_status", Arrays.asList(MomConstants.QUALITY_QAR_CURRENT_STATUS_ISSUE,
				MomConstants.QUALITY_QAR_CURRENT_STATUS_CHECKING, MomConstants.QUALITY_QAR_CURRENT_STATUS_ENTRUST));
		List<QualityQarCheckInvoiceEntity> selectOne = qualityQarCheckInvoiceDao.selectList(queryWrapper);
		// 获取qar编号集合
		List<String> qarNoList = selectOne.stream().map(QualityQarCheckInvoiceEntity::getQarNo)
				.collect(Collectors.toList());
		// 查询qarNo集合中的检验特性数据
		List<QuqlityQarCheckItem> byQarNo = quqlityQarCheckItemDataHandler.getByQarNoList(qarNoList);

		// 创建母本对应检验特性信息
		List<QuqlityQarCheckItem> createQarCheckItem = getQarCheckItem(basicStandardCheckList, null);
		
		
		// 获取qar主键id集合
		List<Long> qarCheckIds = selectOne.stream().map(QualityQarCheckInvoiceEntity::getId)
				.collect(Collectors.toList());
		if (selectOne.size() > 0) {

			// 删除原有的数据集合
			List<QuqlityQarCheckItemEntity> itemEntityList = new ArrayList<QuqlityQarCheckItemEntity>();
			if (byQarNo != null && byQarNo.size() > 0) {
				for (QuqlityQarCheckItem quqlityQarCheckItem : byQarNo) {
					QuqlityQarCheckItemEntity innerData = quqlityQarCheckItem.getInnerData();
					baseEntityDataUtil.deleteBaseEntityData(innerData);
					itemEntityList.add(innerData);
					List<QuqlityQarCheckItem> listItemDetails = quqlityQarCheckItem.getListItemDetails();
					if (listItemDetails != null && listItemDetails.size() > 0) {
						for (QuqlityQarCheckItem quqlityQarCheckItem2 : byQarNo) {
							QuqlityQarCheckItemEntity innerData2 = quqlityQarCheckItem2.getInnerData();
							baseEntityDataUtil.deleteBaseEntityData(innerData2);
							itemEntityList.add(innerData2);
						}
					}
				}
			}
			if (itemEntityList.size() > 0) {
				quqlityQarCheckItemDataHandler.updateBatchById(itemEntityList, itemEntityList.size());
			}

			// 将检验特性的母本数据保存多对应qar编号对应的检验特性数据
			for (String qarNo : qarNoList) {
				for (QuqlityQarCheckItem checkItem : createQarCheckItem) {
					QuqlityQarCheckItem item = cloneCheckItem(checkItem);
					item.getInnerData().setQarNo(qarNo);
					long generateId = idFactory.generateId();
					item.getInnerData().setId(generateId);
					if (item.getListItemDetails() != null && item.getListItemDetails().size() > 0) {
						for (QuqlityQarCheckItem quqlityQarCheckItem : item.getListItemDetails()) {
							QuqlityQarCheckItem cloneCheckItem = cloneCheckItem(quqlityQarCheckItem);
							cloneCheckItem.getInnerData().setQarNo(qarNo);
							cloneCheckItem.getInnerData().setCheckParentId(generateId);
							checkItemList.add(cloneCheckItem);
						}
					}
					if (item != null && item.getInnerData() != null) {
						checkItemList.add(item);
					}
				}

			}
			// 批量查询检验验证数据5435456456
			ResultBean insertBatch = quqlityQarCheckItemDataHandler.insertBatch(checkItemList);
			if (!insertBatch.success) {
				throw new RuntimeException(insertBatch.getMessage());
			}
			// 将母本限售件信息更新到对应qar表中
			// 删除原有的限售件信息
			QueryWrapper<QarRestrictedPartEntity> queryWrapper2 = new QueryWrapper<QarRestrictedPartEntity>();
			queryWrapper2.eq("row_status", 1);
			queryWrapper2.in("qar_no", qarNoList);
			queryWrapper2.eq("is_check", 0);
			boolean remove = qarRestrictedPartDataHandler.remove(queryWrapper2);
			
			// 将满足条件的qar中对应的限售件数据存入qar限售件表中
			// 当没有子限售件
			List<QarRestrictedPartEntity> arrayList = new ArrayList<QarRestrictedPartEntity>();
			for (QualityQarCheckInvoiceEntity qualityQarCheckInvoiceEntity : selectOne) {
				String serialNumber = qualityQarCheckInvoiceEntity.getSerialNumber();
				String[] split = StringUtils.split(serialNumber, ",");
				for (String serial : split) {
					QarRestrictedPartEntity qarRestrictedPartEntity = new QarRestrictedPartEntity();
					qarRestrictedPartEntity.setQarNo(qualityQarCheckInvoiceEntity.getQarNo());
					qarRestrictedPartEntity.setRestrictedProjectPartNo(qualityQarBasicStandardEntity.getPartNumber());
					qarRestrictedPartEntity.setRestrictedSerialNumber(serial);
					qarRestrictedPartEntity.setFinishedProductNo(qualityQarBasicStandardEntity.getRestrictedPartProductNo());
					qarRestrictedPartEntity.setRestrictedPartRequirements(qualityQarBasicStandardEntity.getRestrictedPartRequirements());
					qarRestrictedPartEntity.setIfChildRestrictedPart(qualityQarBasicStandardEntity.getIfChildRestrictedPart());
					arrayList.add(qarRestrictedPartEntity);
				}
			}
			// 新增限售件数据
		if (arrayList.size() > 0) {
			qarRestrictedPartDataHandler.batchInsertData(arrayList);
		}
		}

		// 通过qar主键查询对应的限制要求数据，并删除原有qar检验单
		if (qarNoList.size() > 0) {
			QueryWrapper<QualityPclrTestInvoiceDetailEntity> queryWrapper3 = new QueryWrapper<QualityPclrTestInvoiceDetailEntity>();
			queryWrapper3.eq("row_status", 1);
			queryWrapper3.in("qar_basic_standard_id", qarCheckIds);
			queryWrapper3.eq("requirement_type", MomConstants.QUALITY_QAR_REQUIREMENT_TYPE_LIMIT);
			List<QualityPclrTestInvoiceDetailEntity> selectList = QualityPclrTestInvoiceDetailDao
					.selectList(queryWrapper3);
			if (selectList.size() > 0) {
				selectList.forEach(item -> {
					baseEntityDataUtil.deleteBaseEntityData(item);
				});
				qualityPclrTestInvoiceDetailDataHandler.updateBatchById(selectList, selectList.size());
			}
		}
		// 将限制要求新数据新增到对应表中
		if (basicStandardRequirement.size() > 0) {
			List<QualityPclrTestInvoiceDetailEntity> invoiceDetailList = new ArrayList<QualityPclrTestInvoiceDetailEntity>();
			for (long qarCheckId : qarCheckIds) {
				for (QualityQarBasicStandardRequirement qualityQarBasicStandardRequirement : basicStandardRequirement) {
					// 当是限制要求时新增到对应集合待插入
					if (qualityQarBasicStandardRequirement.getInnerData().getRequirementType().equals(MomConstants.QUALITY_QAR_REQUIREMENT_TYPE_LIMIT)) {
						QualityQarBasicStandardRequirementEntity innerData = qualityQarBasicStandardRequirement
								.getInnerData();
						QualityPclrTestInvoiceDetailEntity qualityPclrTestInvoiceDetailEntity = new QualityPclrTestInvoiceDetailEntity();
						qualityPclrTestInvoiceDetailEntity.setAircraftLimit(innerData.getAircraftLimit());
						qualityPclrTestInvoiceDetailEntity.setMatNumber(innerData.getMatNumber());
						qualityPclrTestInvoiceDetailEntity.setOther(innerData.getOther());
						qualityPclrTestInvoiceDetailEntity.setQarBasicStandardId(qarCheckId);
						qualityPclrTestInvoiceDetailEntity.setRemark(innerData.getRemark());
						qualityPclrTestInvoiceDetailEntity.setRequirementName(innerData.getRequirementName());
						qualityPclrTestInvoiceDetailEntity.setRequirementType(innerData.getRequirementType());
						qualityPclrTestInvoiceDetailEntity.setTestItemQuatity(innerData.getTestItemQuatity());
						baseEntityDataUtil.setBaseEntityData(qualityPclrTestInvoiceDetailEntity);
						invoiceDetailList.add(qualityPclrTestInvoiceDetailEntity);
					}
				}
			}
			qualityPclrTestInvoiceDetailDataHandler.saveBatch(invoiceDetailList, invoiceDetailList.size());
		}
	}

	// 复制对象
	public QuqlityQarCheckItem cloneCheckItem(QuqlityQarCheckItem item) {
		QuqlityQarCheckItem quqlityQarCheckItem = new QuqlityQarCheckItem();
		QuqlityQarCheckItemEntity innerData = item.getInnerData();
		long attachmentGroupId = innerData.getAttachmentGroupId();
		System.out.println("=================> " + attachmentGroupId);
		QuqlityQarCheckItemEntity quqlityQarCheckItemEntity = new QuqlityQarCheckItemEntity();
		quqlityQarCheckItem.setInnerData(quqlityQarCheckItemEntity);
		quqlityQarCheckItem.getInnerData().setAttachmentGroupId(attachmentGroupId);
		quqlityQarCheckItem.getInnerData().setCheckDetail(innerData.getCheckDetail());
		quqlityQarCheckItem.getInnerData().setCheckItem(innerData.getCheckItem());
		quqlityQarCheckItem.getInnerData().setCheckParentId(innerData.getCheckParentId());
		quqlityQarCheckItem.getInnerData().setCheckPictureName(innerData.getCheckPictureName());
		quqlityQarCheckItem.getInnerData().setCheckPicturePath(innerData.getCheckPicturePath());
		quqlityQarCheckItem.getInnerData().setQarNo(innerData.getQarNo());
		quqlityQarCheckItem.getInnerData().setRemark(innerData.getRemark());
		quqlityQarCheckItem.getInnerData().setResult(innerData.getResult());
		quqlityQarCheckItem.getInnerData().setRowStatus(innerData.getRowStatus());
		quqlityQarCheckItem.getInnerData().setType(innerData.getType());
		quqlityQarCheckItem.getInnerData().setAttachmentGroupId(innerData.getAttachmentGroupId());
		quqlityQarCheckItem.getInnerData().setGroupId(innerData.getGroupId());
		if (item.getListItemDetails() != null && item.getListItemDetails().size() > 0) {
			List<QuqlityQarCheckItem> checkItemList = new ArrayList<QuqlityQarCheckItem>();
			for (QuqlityQarCheckItem QuqlityQarCheckItem : item.getListItemDetails()) {
				QuqlityQarCheckItem quqlityQarCheckItem1 = new QuqlityQarCheckItem();
				QuqlityQarCheckItemEntity innerData1 = QuqlityQarCheckItem.getInnerData();
				QuqlityQarCheckItemEntity quqlityQarCheckItemEntity1 = new QuqlityQarCheckItemEntity();
				quqlityQarCheckItem1.setInnerData(quqlityQarCheckItemEntity1);
				quqlityQarCheckItem1.getInnerData().setAttachmentGroupId(innerData1.getAttachmentGroupId());
				quqlityQarCheckItem1.getInnerData().setCheckDetail(innerData1.getCheckDetail());
				quqlityQarCheckItem1.getInnerData().setCheckItem(innerData1.getCheckItem());
				quqlityQarCheckItem1.getInnerData().setCheckPictureName(innerData1.getCheckPictureName());
				quqlityQarCheckItem1.getInnerData().setCheckPicturePath(innerData1.getCheckPicturePath());
				quqlityQarCheckItem1.getInnerData().setQarNo(innerData1.getQarNo());
				quqlityQarCheckItem1.getInnerData().setRemark(innerData1.getRemark());
				quqlityQarCheckItem1.getInnerData().setResult(innerData1.getResult());
				quqlityQarCheckItem1.getInnerData().setRowStatus(innerData1.getRowStatus());
				quqlityQarCheckItem1.getInnerData().setType(innerData1.getType());
				quqlityQarCheckItem1.getInnerData().setAttachmentGroupId(innerData1.getAttachmentGroupId());
				quqlityQarCheckItem1.getInnerData().setGroupId(innerData1.getGroupId());
				checkItemList.add(quqlityQarCheckItem1);
			}
			quqlityQarCheckItem.setListItemDetails(checkItemList);
		}
		return quqlityQarCheckItem;
	}

	/**
	 * 将qar的当前状态为冻结更改
	 * 
	 * 状态在MomConstants类中
	 * 
	 **/

	public void updateCurrentStatus(long qarBasicStandardId, String currentStatus) {
		QueryWrapper<QualityQarCheckInvoiceEntity> queryWrapper = new QueryWrapper<QualityQarCheckInvoiceEntity>();
		queryWrapper.eq("qar_basic_standard_id", qarBasicStandardId);
		queryWrapper.eq("row_status", 1);
		// 只查询已发布，检验中，委托中三个状态数据
		queryWrapper.in("current_status", Arrays.asList(MomConstants.QUALITY_QAR_CURRENT_STATUS_ISSUE,
				MomConstants.QUALITY_QAR_CURRENT_STATUS_CHECKING, MomConstants.QUALITY_QAR_CURRENT_STATUS_ENTRUST));
		List<QualityQarCheckInvoiceEntity> selectOne = qualityQarCheckInvoiceDao.selectList(queryWrapper);
		if (selectOne.size() > 0) {
			selectOne.forEach(item -> {
				item.setIsFrozen(currentStatus);
				baseEntityDataUtil.updateBaseEntityData(item);
			});
			qualityQarCheckInvoiceDataHandler.updateBatchById(selectOne, selectOne.size());
		}
	}
	/**
	 * 校验纠正措施平台传入的qar是否在已发布，检验中，委托中状态，当不是时返回数据
	 * **/
	public ResultBean validateQarStatus(List<String> qarNoList) {
		ResultBean resultBean = new ResultBean(true);
		QueryWrapper<QualityQarCheckInvoiceEntity> queryWrapper = new QueryWrapper<QualityQarCheckInvoiceEntity>();
		queryWrapper.eq("row_status", 1);
		queryWrapper.in("qar_no", qarNoList);
		List<QualityQarCheckInvoiceEntity> selectList = qualityQarCheckInvoiceDao.selectList(queryWrapper);
		List<String> checkStatus = Arrays.asList(MomConstants.QUALITY_QAR_CURRENT_STATUS_ISSUE,
				MomConstants.QUALITY_QAR_CURRENT_STATUS_CHECKING, MomConstants.QUALITY_QAR_CURRENT_STATUS_ENTRUST);
		if (selectList.size() > 0) {
			for (QualityQarCheckInvoiceEntity qualityQarCheckInvoiceEntity : selectList) {
				boolean contains = checkStatus.contains(qualityQarCheckInvoiceEntity.getCurrentStatus());
				if (!contains) {
					String invoiceByStatus = ParamUtils.getInvoiceByStatus(qualityQarCheckInvoiceEntity.getCurrentStatus());
					resultBean.setErrorMessge("qar编号  "+qualityQarCheckInvoiceEntity.getQarNo()+"  状态为  "+invoiceByStatus+" 无法执行当前操作！");
				}
			}
		}
		return resultBean;
	}
}
